VBA Range Question

  • Thread starter Thread starter Don
  • Start date Start date
D

Don

In VBA how do I find the first and last row number in a range?

I need to perform various calculations on different segments of a range
(single column range) and my first problem is to identify the first and last
row. Then I'll loop through the rows and perform various calculations.

Thanks.

Don

P.S. Is there a VBA reference somewhere that would help me answer questions
like above? Using the VBA help facility doesn't seem to help, probably
because of my low expertise in VBA.
 
Look at this:

Sub aaa()
Dim MyRange As Range
Set MyRange = Range("A10:A20")
FirstRow = MyRange.Row
If FirstRow <> 1 Then
LastRow = MyRange.Rows.Count + FirstRow - 1
Else
LastRow = MyRange.Rows.Count
End If
MsgBox ("FirstRow: " & FirstRow & vbLf & "LastRow: " & LastRow)

End Sub

Hopes this helps.
....
Per
 
Try this...

Dim R As Range, FirstRow As Long, LastRow As Long
.....
.....
' Set your range to a Range variable, no
' matter how the range gets specified.
Set R = Range("A3:A345")
' Then use cell iterating to move within the range
FirstRow = R(1).Row
LastRow = R(R.Count).Row
 
Back
Top