using RANGE object in multiple-area range

  • Thread starter Thread starter TerryT
  • Start date Start date
T

TerryT

If I want to search a "block" of cells this code will search across columns
then by rows, is there anyway to search all of the rows in a column before
moving to the next row? In other words colum A rows1 1-10, col B rows
1-10...etc instead of A1, B1, C1, A2, B2, C2
Thanks

Function jjj()
Dim terry As Range
Set terry = Worksheets(1).Range("A1:C3")
For Each x In terry
MsgBox x.Value
Next x
End Function
 
You can use this

Set terry = Worksheets(1).Range("A1:A10,B1:B10")
 
TerryT said:
If I want to search a "block" of cells this code will search across columns
then by rows, is there anyway to search all of the rows in a column before
moving to the next row? In other words colum A rows1 1-10, col B rows
1-10...etc instead of A1, B1, C1, A2, B2, C2
Thanks

Function jjj()
Dim terry As Range
Set terry = Worksheets(1).Range("A1:C3")
For Each x In terry
MsgBox x.Value
Next x
End Function

I don't know if it's useful for you, but the For...Each structure
traverses arrays differently from ranges; down the columns:

Function jjj()
Dim terry As Variant
terry = Worksheets(1).Range("A1:C3")
For Each x In terry
MsgBox x
Next x
End Function

Alan Beban
 
Would this idea help?

Sub Demo()
Dim Col As Range
Dim Cell As Range
For Each Col In Range("A1:C3").Columns
For Each Cell In Col.Cells
Debug.Print Cell.Address
Next Cell
Next Col
Debug.Print
End Sub

Returns:
$A$1
$A$2
$A$3
$B$1
$B$2
....
$C$3

HTH
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top