Hi and thanks in advance for your help.
I am trying to refer to a range indirectly like the following:
I have a range ("Ranges") that is a list of names of many other ranges. As my macro is looping through these ranges I want to be able to reference that name and look up its corresponding range.
It is giving me an error when referencing that text as a range, but if I input directly, it works fine. To be explicit,
This works:
Set CRange = ThisWorkbook.Sheets("Sheet1").Range("Range1")
This doesn't:
Set CRange = ThisWorkbook.Sheets("Sheet1").Range(ID)
even if ID = "Range1"
I can't reference the address because I want it to be dynamic, so I must use the name.
Any suggestions?
Any help would be appreciated and get me some better sleep. Thanks.
Mod's note : code tags added for you - this time
I am trying to refer to a range indirectly like the following:
I have a range ("Ranges") that is a list of names of many other ranges. As my macro is looping through these ranges I want to be able to reference that name and look up its corresponding range.
Code:
Sub Indirect_Range()
Dim ID as String
Dim CRange as Range
ID = ThisWorkbook.Sheets("Sheet2").Range("Ranges").Rows(i).Value
'ID = "Range1"
Set CRange = ThisWorkbook.Sheets("Sheet1").Range(ID)
End Sub
It is giving me an error when referencing that text as a range, but if I input directly, it works fine. To be explicit,
This works:
Set CRange = ThisWorkbook.Sheets("Sheet1").Range("Range1")
This doesn't:
Set CRange = ThisWorkbook.Sheets("Sheet1").Range(ID)
even if ID = "Range1"
I can't reference the address because I want it to be dynamic, so I must use the name.
Any suggestions?
Any help would be appreciated and get me some better sleep. Thanks.
Mod's note : code tags added for you - this time