Get second last row?

TheWennerWoman

Active Member
Joined
Aug 1, 2019
Messages
303
Office Version
  1. 365
Platform
  1. Windows
I have some data in column B. It starts at row 14 and the last possible row of data is row 63.

However, there is text in cell B66 (along the lines of "by submitting this form you confirm you have read the expenses terms and conditions").

So column B might have data all the way down to B63, it might only go to B20, it's fluid.

How can I ignore B66 and just get the second last row?

Many thanks as always.
 

Excel Facts

What is =ROMAN(40) in Excel?
The Roman numeral for 40 is XL. Bill "MrExcel" Jelen's 40th book was called MrExcel XL.
If you are happy to hard code B66 then something like this will work.
Note: Consider at least giving B66 a range name and using that so if you insert rows it will still work.

VBA Code:
    Dim lastRow As Long
    lastRow = Range("B66").End(xlUp).Row   ' preferably add a sheet reference before the "Range"
 
Upvote 1
something like this:
VBA Code:
Function slr(sh As Worksheet)
    With sh.Range("B66")
        If IsEmpty(.Offset(-1).Value) Then
            slr = .End(xlUp).Row
        Else
            slr = 65
        End If
    End With
End Function
call it like this in the immediate window of VBE:
VBA Code:
?slr (thisworkbook.worksheets("Sheet1"))
 
Upvote 1
on a second thought, if you are certain that B63 is the last possible entry, maybe this approach is better:
VBA Code:
Function slr(sh As Worksheet)
    With sh.Range("B63")
        If IsEmpty(.Value) Then
            slr = .End(xlUp).Row
        Else
            slr = .Row
        End If
    End With
End Function
 
Upvote 1
Solution

Forum statistics

Threads
1,223,903
Messages
6,175,289
Members
452,631
Latest member
a_potato

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top