A family of Microsoft spreadsheet software with tools for analyzing, charting, and communicating data.
Use
Set rngOccasion = Range("A89:A103,L89:L103")
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
Hi
need to loop through 2 columns, top to botton from the first and then top to bottom second. Managed to do just one range:
Set rngOccasion = Range("A89:A103")
this loops ok if i declare one range only
For Each cl In rngOccasion.Cells
If cl.Value = targetDate Then
flagNewDate = False
Exit For
End If
Next cl
need to go through 2 ranges
Set rngOccasion = Range("A89:A103", "L89:L103")
Thanks
A family of Microsoft spreadsheet software with tools for analyzing, charting, and communicating data.
Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.
Answer accepted by question author
Use
Set rngOccasion = Range("A89:A103,L89:L103")
Re: ranges
Sub Testing()
Dim rngOccasion As Excel.Range
Dim rArea As Excel.Range
Dim rCell As Excel.Range
Set rngOccasion = Range("A89:A103", "L89:L103")
VBA.MsgBox "Areas " & rngOccasion.Areas.Count & vbCr & _
"Cells " & rngOccasion.Cells.Count
Set rngOccasion = Range("A89:A103, L89:L103")
VBA.MsgBox "Areas " & rngOccasion.Areas.Count & vbCr & _
"Cells " & rngOccasion.Cells.Count
For Each rArea In rngOccasion
For Each rCell In rArea
'do something
Next 'rCell
Next 'rArea
End Sub
'---
Info...
Reference Meaning
'Range("A1") Cell A1
'Range("A1:B5") Cells A1 through B5
'Range("C5:D9,G9:H16") A multiple-area selection
'Range("A:A") Column A
'Range("1:1") Row one
'Range("A:C") Columns A through C
'Range("1:5") Rows one through five
'Range("1:1,3:3,8:8") Rows one, three, and eight
'Range("A:A,C:C,F:F") Columns A, C, and F
'---
NLtL
Thanks for that, appreciate it
Thanks again!
Re: ranges
Sub Testing()
Dim rngOccasion As Excel.Range
Dim rArea As Excel.Range
Dim rCell As Excel.Range
Set rngOccasion = Range("A89:A103", "L89:L103")
VBA.MsgBox "Areas " & rngOccasion.Areas.Count & vbCr & _
"Cells " & rngOccasion.Cells.Count
Set rngOccasion = Range("A89:A103, L89:L103")
VBA.MsgBox "Areas " & rngOccasion.Areas.Count & vbCr & _
"Cells " & rngOccasion.Cells.Count
For Each rArea In rngOccasion
For Each rCell In rArea
'do something
Next 'rCell
Next 'rArea
End Sub
'---
Info...
Reference Meaning
'Range("A1") Cell A1
'Range("A1:B5") Cells A1 through B5
'Range("C5:D9,G9:H16") A multiple-area selection
'Range("A:A") Column A
'Range("1:1") Row one
'Range("A:C") Columns A through C
'Range("1:5") Rows one through five
'Range("1:1,3:3,8:8") Rows one, three, and eight
'Range("A:A,C:C,F:F") Columns A, C, and F
'---