The main reason for asking (and this is probably something I'm doing wrong) is because I have written loads of macros refering to cells ranges and subsequently moved these cells and altered the layout of the work sheets around to look more pleasing / functional and although the cell references in formulas will update, the cell ranges in VBA do not seem to.
That is expected behavior. As I said, Excel and VBA are different programs, so changes that you make to your Excel sheet will have no impact on your VBA code.
If you do that a lot, here is what I recommend doing. Use Range variables, and define your ranges at the top of your code, then in the body of your code, write it against the range variable names and not hard-coded ranges. Then, if you change the layout of your sheet, you would only need to change the range reference values at the top of your code.
For example, let's say that we have a Title row that we want to bold and underline. That (very simplified) section of code may look something like this:
Code:
Sub Test()
' Set title range
Dim rngTitle As Range
[COLOR=#ff0000] Set rngTitle = Range("A1:C1")[/COLOR]
' Write code against range to bold and underline
With rngTitle
.Font.Bold = True
.Font.Underline = xlUnderlineStyleSingle
End With
End Sub
And maybe you will be doing other things to this Title row too, so you might have more code below that. If you were to ever change the title row, you would then just need to update that one line in red at the top, instead of a whole bunch of hard-coded range references down in your code.
Also, if you have some sections of code dependent on other selections, you may be able to use things like
Offset and
CurrentRegion to move relative to another range reference, instead of hard-coding those references. You can Google those for more details.