Hello!
In an application, I use VBA to update named ranges. The ranges are used in a series of data validation functions. Unfortunately I can't use dynamic named ranges, otherwise the data validation won't work.
I wrote a function to update the named ranges, and put a function call in the Worksheet_Deactivate event. For each range the code looks like this:
That worked fine until I had to insert some columns into the Class_Schedule sheet. Because I had to move some of the ranges, the column number and letter changed. It took me some serious time to sort out all of the code changes. How can I update the range without hard coding the column number?
I tried the following:
That works, but the "E" in ("Class_Schedule!E65536") is still hard-coded. I can't figure out how to extract a value of "E" from the range properties. I tried
but that returns a value of "5"
Help?
In an application, I use VBA to update named ranges. The ranges are used in a series of data validation functions. Unfortunately I can't use dynamic named ranges, otherwise the data validation won't work.
I wrote a function to update the named ranges, and put a function call in the Worksheet_Deactivate event. For each range the code looks like this:
Code:
LastRow = Range("Class_Schedule!E65536").End(xlUp).Row
ActiveWorkbook.Names("class").RefersToR1C1 = "=Class_Schedule!R2C5:R" & LastRow & "C5"
That worked fine until I had to insert some columns into the Class_Schedule sheet. Because I had to move some of the ranges, the column number and letter changed. It took me some serious time to sort out all of the code changes. How can I update the range without hard coding the column number?
I tried the following:
Code:
LastRow = Range("Class_Schedule!E65536").End(xlUp).Row
Column = ActiveWorkbook.Names("class").RefersToRange.Column
ActiveWorkbook.Names("class").RefersToR1C1 = "=Class_Schedule!R2C" & Column & ":R" & LastRow & "C" & Column
That works, but the "E" in ("Class_Schedule!E65536") is still hard-coded. I can't figure out how to extract a value of "E" from the range properties. I tried
Code:
ActiveWorkbook.Names("class").RefersToRange.Column
but that returns a value of "5"
Help?