ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Changing Range & Cell refs. (https://www.excelbanter.com/excel-programming/364949-changing-range-cell-refs.html)

Stella

Changing Range & Cell refs.
 
Is there any way to make a macro automatically "follow" changes to the
worksheet itself?

For example, I might have a macro with an instruction such as

Range("C5") = x

But then I need to modify the sheet and insert columns and/or rows that
requires the value 'x' to now appear in G9 but I have to manually change the
macro instructions.

I'm sure that there must be a way to avoid this hassle but how?

TIA
Stella



Gary''s Student

Changing Range & Cell refs.
 
Use a Named Range:

Let's say that in the worksheet we created the name benine for =Sheet1!$B$9
the macro:

Sub ordinate()
MsgBox (Range("benine").Value)
MsgBox (Range("benine").Address)
End Sub

will display the contents and address of B9. If you insert rows before B9,
the name in the worksheet will automatically adjust and the macro will track
to the new cell.
--
Gary''s Student


"Stella" wrote:

Is there any way to make a macro automatically "follow" changes to the
worksheet itself?

For example, I might have a macro with an instruction such as

Range("C5") = x

But then I need to modify the sheet and insert columns and/or rows that
requires the value 'x' to now appear in G9 but I have to manually change the
macro instructions.

I'm sure that there must be a way to avoid this hassle but how?

TIA
Stella





All times are GMT +1. The time now is 12:06 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com