Find the last specific value in a column

Nelson78

Well-known Member
Joined
Sep 11, 2017
Messages
526
Office Version
  1. 2007
Good morning.

In my work the column D is populated by a word, for example "Europe", a lot of times.
I need a vba code in order to find - and select - the last cell of that column populated by "Europe".

My attempt is just a manual operation recorded by the macro recorder, now I need a help for bigger files.

Thank's.

Code:
Sub find_last()
    Columns("D:D").Select
    Cells.Find(What:="europe", After:=ActiveCell, LookIn:=xlFormulas, LookAt:= _
        xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=False _
        , SearchFormat:=False).Activate
    Cells.FindNext(After:=ActiveCell).Activate
    Cells.FindNext(After:=ActiveCell).Activate
End Sub
 
Last edited:

Excel Facts

Save Often
If you start asking yourself if now is a good time to save your Excel workbook, the answer is Yes
Hi
How about
Code:
Sub lastValue()

    Dim Rng As Range

    Set Rng = Range("D" & Rows.Count).End(xlUp).Offset(1)
    Columns("D").Find("Europe", After:=Rng, SearchOrder:=xlByRows, SearchDirection:=xlPrevious, MatchCase:=False, _
         SearchFormat:=False).Select
        

End Sub
 
Upvote 0
You can create an Excel formula by placing the following code in a new Module:

Code:
Public Function findlast(ByVal colRange As Range, ByVal FindWord As String)
Dim LastRow As Long

LastRow = Cells(Rows.Count, colRange.Column).End(xlUp).Row 'finds the last row in the user-specified column
For i = LastRow To 1 Step -1
    If Cells(i, colRange.Column) = FindWord Then 'loops from the last row in the column to the first to check if it matches user-specified word
        
        findlast = i
        Exit Function
        
    End If
 
Next i

findlast = "Word not found"

End Function

So now that you've done that, if you want to find the last entry in column D, which says Europe, you'd have to type in the following formula anywhere on your spreadsheet: =findlast(D:D,"Europe") . This is obviously customisable.
 
Upvote 0
The tests done until now are positive in both cases.

Thank you for the solutions.
 
Last edited:
Upvote 0
Glad we could help & thanks for the feedback
 
Upvote 0
Now, I'm struggling with something similar.

Autofilters are applied in my sheet. For the column D, I've filtered the empty values.
Now, with autofilters applied, I need to select the first empty cell.

My attempt is not successful: the selection, infact, is always on cell D2, regardless of its value.

Code:
    ActiveSheet.Range("$D$1:$D$10000").AutoFilter Field:=1, Criteria1:="="
    Range("D1").Offset(1, 0).Select
 
Upvote 0
Perhaps this could be one of the right solutions.

Code:
ActiveSheet.Range("$A$1:$E$10000").AutoFilter Field:=4, Criteria1:="="
Columns("D:D").Select
Range("D2:D10000").SpecialCells(xlCellTypeVisible)(1).Select
 
Upvote 0
Better.

Code:
ActiveSheet.Range("$A$1:$E$10000").AutoFilter Field:=4, Criteria1:="="
Range("D2:D10000").SpecialCells(xlCellTypeVisible)(1).Select
 
Upvote 0

Forum statistics

Threads
1,223,903
Messages
6,175,287
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