Maximum non-blank row in a specific range as a variable
On Nov 19, 4:18 am, "Per Jessen" wrote:
---------Cut -------
What I have is data that is in the range U5:AU25 and for each column
the last non-blank row will vary. For example in column U the last
non-blank row might be 27, and V the last non-blank row might be 25, a
in W the last non-blank row might be 30. I need to return a variable
with the highest occupied non-blank row number. For my example the
variable would return a 30 since between U, V and W the highest row
number is 30. (Sorry for being unclear on that.) I do know how to
return the highest row number for a single column but thought there
might be a snazzy way to do that for my example of finding the highest
row number between a multiple column sample set.
Thanks,
Chet
Hi Chet
This routine loop through columns U:UA and return the largest row number.
Hi Chet
Just a little correction. Try this code instead:
Option Explicit
Dim Target As Range
Dim c As Variant
Dim tRow As Long
Dim lRow As Long
Dim msg As String
Dim tColumn as Long
Dim fRow As Long
Sub LastRow()
Set Target = Range("U5:UA25")
tColumn = Target.Column
fRow = Target.Row
For Each c In Target.Columns
tRow = Cells(fRow, tColumn).End(xlDown).Row
If tRow lRow Then lRow = tRow
tColumn = tColumn + 1
Debug.Print tRow
Next
msg = MsgBox("Last row = " & lRow)
End Sub- Hide quoted text -
- Show quoted text -
Thanks much for trying. I was hoping for a one-liner piece of code to
do it with. I am able to code this myself also with a few lines of
code.
Best regards,
Chet
|