Always evaluate last row of data

tiredofit

Well-known Member
Joined
Apr 11, 2013
Messages
1,913
Office Version
  1. 365
  2. 2019
Platform
  1. Windows
Assume I have some data on Sheet1 as follows:


Code:
Apples
Apples
Oranges
Pineapples
Peaches
Coconuts


Using the code below, the last row evaluates to 6, correctly:


Code:
Public Function LRow(ByRef wks As Worksheet) As Long

    On Error GoTo Correction

        With wks
        
            LRow = .Cells.Find(What:="*", _
                               After:=.Cells(Rows.Count, Columns.Count), _
                               SearchDirection:=xlPrevious, _
                               SearchOrder:=xlByRows).Row
            
        End With

    On Error GoTo 0

        Exit Function
Correction:
        LRow = 1

    Resume Next
End Function


However, if the user were to apply a filter to the data first and only want Apples, using the code above evaluates to 2.


What I want is to some function to evaluate to 6, regardless of whether the user has applied a filter to the data.


I don't want to turn off the autofilter by adding:


Code:
Sheet1.AutoFilterMode = False


because I assume the user wants to have the autofilter active.


Can it be done?


Thanks
 

Excel Facts

Whats the difference between CONCAT and CONCATENATE?
The newer CONCAT function can reference a range of cells. =CONCATENATE(A1,A2,A3,A4,A5) becomes =CONCAT(A1:A5)
Try:
Code:
   LRow = .Cells.Find(What:="*", _
                               After:=.[COLOR=#0000cd]Cells(1, 1)[/COLOR], _
                               SearchDirection:=xlPrevious, _
                               SearchOrder:=xlByRows).Row
 
Upvote 0
You're welcome & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,223,228
Messages
6,170,871
Members
452,363
Latest member
merico17

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