MacroMan007
New Member
- Joined
- Aug 5, 2005
- Messages
- 35
Hello and thanks in advance for any help you can give me.
What I am trying to do, is to simply change the cell reference of a named range from 1 column to the immediate column to the right, but with VBA. I have Googled this, but keep on finding ways to make a dynamic named range and I don't believe that's exactly what I'm looking for here.
So, if the Named Range COpC is in cell Y2 (R2C25), I want to change it to Z2 (R2C26), without me having to manually change the code in the VBA editor. So, the next time the code is run, the named range will refer to Z2 and I will want it to change to AA2 and so on...
Is deleting the named range and recreating it one column to its right best, or is there a way to change the reference dynamically with VB.
Here's the code I have so far that I have to manually change after running it each time.
Sub ChangeRef()
Application.Goto Reference:="COpC"
'Current Location of COpC = Y2 or R2C25
ActiveWorkbook.Names("COpC").Delete
ActiveCell.Offset(0, 1).Range("A1").Select
'New location will always be 1 column to the right.
ActiveWorkbook.Names.Add Name:="COpC", RefersToR1C1:= _
"='OpsPart'!R2C26"
End Sub
Anyway, thanks for your help.
Jay
What I am trying to do, is to simply change the cell reference of a named range from 1 column to the immediate column to the right, but with VBA. I have Googled this, but keep on finding ways to make a dynamic named range and I don't believe that's exactly what I'm looking for here.
So, if the Named Range COpC is in cell Y2 (R2C25), I want to change it to Z2 (R2C26), without me having to manually change the code in the VBA editor. So, the next time the code is run, the named range will refer to Z2 and I will want it to change to AA2 and so on...
Is deleting the named range and recreating it one column to its right best, or is there a way to change the reference dynamically with VB.
Here's the code I have so far that I have to manually change after running it each time.
Sub ChangeRef()
Application.Goto Reference:="COpC"
'Current Location of COpC = Y2 or R2C25
ActiveWorkbook.Names("COpC").Delete
ActiveCell.Offset(0, 1).Range("A1").Select
'New location will always be 1 column to the right.
ActiveWorkbook.Names.Add Name:="COpC", RefersToR1C1:= _
"='OpsPart'!R2C26"
End Sub
Anyway, thanks for your help.
Jay