Public Schedule Face-to-Face & Online Instructor-Led Training - View dates & book

effect adding column worksheet

Forum home » Delegate support and help forum » Microsoft Excel VBA Training and help » Effect of adding a column on a worksheet to all column refs in V

Effect of adding a column on a worksheet to all column refs in V

ResolvedVersion 2016

Diane has attended:
Excel VBA Introduction course
Excel VBA Intermediate course
Excel VBA Advanced course

Effect of adding a column on a worksheet to all column refs in V

I was about to add a column to my worksheet when it occurred to me any referencing in vb to column numbers e.g. in my arrays; in my offsets etc will now be incorrect. I could of course add the column on the right, but maybe it makes more logical sense for the column to be adjacent to another mid range. I'm thinking this must be quite a common requirement, what would be the recommended way to write vb to cope with this?

RE: Effect of adding a column on a worksheet to all column refs

Hi Diane

You're quite right it is a common problem when amending spreadsheets with macro's attached.

Best practice emphases the importance of a change log, to keep track of changes and the impact they will have. This will help you quickly identify areas and take the appropriate steps when coding.

Additionally,identify something other than the column letter which will make it easier for Excel to find e.g. the Heading of the table "Employee Name" or "Invoice Amount" this way if the heading is moved Excel will still find it and move the relevant section.

Kind regards

Dennis

RE: Effect of adding a column on a worksheet to all column refs

Thanks Dennis, I will change my references to column name wherever it is possible. There is no way similar around this for arrays, is there?.

Di

RE: Effect of adding a column on a worksheet to all column refs

Hi Diane

The principle applies for arrays too. You could consider using dynamic named ranges to name the range on the spreadsheet and then assign the range to an array in VBA.

Link to a tutorial on dynamic named ranges https://www.excel-easy.com/examples/dynamic-named-range.html

Regards

Dennis

Tue 14 Apr 2020: Automatically marked as resolved.

 

Training courses

Training information:

Welcome. Please choose your application (eg. Excel) and then post your question.

Our Microsoft Qualified trainers will then respond within 24 hours (working days).

Frequently Asked Questions
What does 'Resolved' mean?

Any suggestions, questions or comments? Please post in the Improve the forum thread.

Excel tip:

Hiding a worksheet in Excel

Want to circulate an Excel workbook file but keep certain worksheets hidden from your colleagues' view?

You can do so by bringing up the sheet you wish to hide on your screen; then going to Format - Sheet - Hide.

It will not be immediately obvious that a sheet is hidden from view unless perhaps the sheet are still labelled Sheet 1, Sheet 2 etc.

To display the sheet again, you can go to Format - Sheet - Unhide on any of the other sheets in the workbook. A dialogue box will appear, allowing you to select the hidden sheet/s. Click OK to make the sheet/s reappear again.

View all Excel hints and tips

Connect with us:

0207 987 3777

Call for assistance

Request Callback

We will call you back

Server loaded in 0.09 secs.