I want to load some ranges into a dictionary and then resize the ranges.
I was originally passing the rng.address to Dictionary but realized that I needed access to the Resize method of the range to resize it. So I switched to adding the range itself.
I am getting a runtime error 424 Object Required in the For Each loop. How do I loop through the actual range variables that I have added to the Dictionary to access and edit their cell addresses?
I was originally passing the rng.address to Dictionary but realized that I needed access to the Resize method of the range to resize it. So I switched to adding the range itself.
I am getting a runtime error 424 Object Required in the For Each loop. How do I loop through the actual range variables that I have added to the Dictionary to access and edit their cell addresses?
VBA Code:
Sub TEST()
Dim rnglblcoll as Dictionary
Dim rng as Range
Set rnglblcoll = New Scripting.Dictionary
Set rng = Range("NamedRange1")
rnglblcoll.Add item:=rng, Key:="Label1"
Set rng = Nothing
Set rng = Range("NamedRange2")
rnglblcoll.Add item:=rng, Key:="Label2"
Set rng = Nothing
Set rng = Range("NamedRange3")
rnglblcoll.Add item:=rng, Key:="Label3"
'Update Address in Dictionary
For Each rng In rnglblcoll
rng = rng.Address.Resize(1, 1)
Next
End Sub