How to step through top row of a Range object

  • Thread starter Thread starter TBA
  • Start date Start date
T

TBA

Excel 2000
Windows 2k Pro

Suppose I have a Range variable MyRange, and it is set to a table on Sheet1.

Dim MyRange As Range, cell As Range
Dim a As Integer

Set MyRange = Range("A1").CurrentRegion

Now I want to step through the headers for this range, and the headers are
all in row 1. How would I do this? I tried:

a = 0
For Each cell in MyRange.Rows(1)
a = a + 1
[more code]
Next cell

I'm know that the "MyRange.Rows(1)" part of the For-Next loop is wrong - how
should it be? Any help appreciated.

-gk-
 
One way

Set myrange = Range("A1").CurrentRegion
For Hcell = 1 To myrange.Columns.Count
MsgBox Cells(1, Hcell)
Next
 
Another way:

Option Explicit
Sub testme01()

Dim a As Long
Dim cell As Range
Dim myRange As Range

Set myRange = Range("a1").CurrentRegion

a = 0
For Each cell In myRange.Rows(1).Cells
MsgBox cell.Address
a = a + 1
'[more code]
Next cell

End Sub

Excel 2000
Windows 2k Pro

Suppose I have a Range variable MyRange, and it is set to a table on Sheet1.

Dim MyRange As Range, cell As Range
Dim a As Integer

Set MyRange = Range("A1").CurrentRegion

Now I want to step through the headers for this range, and the headers are
all in row 1. How would I do this? I tried:

a = 0
For Each cell in MyRange.Rows(1)
a = a + 1
[more code]
Next cell

I'm know that the "MyRange.Rows(1)" part of the For-Next loop is wrong - how
should it be? Any help appreciated.

-gk-
 
Back
Top