I am try to fill some gaps in my VBA knowledege and I am confused as to why this code does not work in VBA:
Sub RangeTest()
Dim TemplateRange As Range
Set TemplateRange = ThisWorkbook.Worksheets("Template").Range("A7:BO200")
For Each thing In ThisWorkbook.Worksheets("Template").Range("A7:BO200").Columns(2)
Debug.Print thing
Next thing
End Sub
Is a range not a group of other objects that you can iterate through? Thinking about it now, I guess it might not be. I noticed that I can iterate through the .values of the range. But I guess the range itself is simply one object?
You must say which collection in the .Columns()
object you want to use; in this case, the .Cells
collection seems what you want:
Sub RangeTest()
Dim TemplateRange As Range
Set TemplateRange = ThisWorkbook.Worksheets("Template").Range("A7:BO200")
For Each thing In TemplateRange.Columns(2).Cells
' This is what you want to use, I think --^^^^^^
Debug.Print thing
Next thing
End Sub
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments