Go to last row where column A has a defined value

Malen Steptoe

New Member
Joined
Feb 4, 2019
Messages
2
I have a user form with a text field where the date is entered. I want to find the last instance of that date, insert a row beneath it and add the data in the user form into that row.

How do I go to the last row with the same value as that in the text field? I know how to do it for the last row with data in it but not specific data.

Cheers in advance
 

Excel Facts

Ambidextrous Undo
Undo last command with Ctrl+Z or Alt+Backspace. If you use the Undo icon in the QAT, open the drop-down arrow to undo up to 100 steps.
Hello and welcome.

You would use the Range.Find method ensuring the direction is set to xlPrevious.

So for example this code looks for the last instance of 01/12/19 in column A:

Code:
Sub LastDate()
    Dim d As Date, rFind As Range
    
    
    d = "01/12/19"
    
    Set rFind = Range("A:A").Find(What:=d, SearchDirection:=xlPrevious)
    
    If Not rFind Is Nothing Then
        'Display the address of last instance of the date
        MsgBox rFind.Address
    Else
        MsgBox "Not Found"
    End If
    
    
End Sub
 
Last edited:
Upvote 0
Hello and welcome.

You would use the Range.Find method ensuring the direction is set to xlPrevious.

So for example this code looks for the last instance of 01/12/19 in column A:

Code:
Sub LastDate()
    Dim d As Date, rFind As Range
    
    
    d = "01/12/19"
    
    Set rFind = Range("A:A").Find(What:=d, SearchDirection:=xlPrevious)
    
    If Not rFind Is Nothing Then
        'Display the address of last instance of the date
        MsgBox rFind.Address
    Else
        MsgBox "Not Found"
    End If
    
    
End Sub

That worked for find it so thank you for that. What I would like to do now is insert a new row below the located cell instead of the msgbox. I thought that would be relativity straight forward part but it seems to need to select the entire row initially and I cant work out how I would write that so that it was based on the found cell.
 
Upvote 0
Apologies I missed that. Straight forward enough:

Code:
Sub LastDate()
    Dim d As Date, rFind As Range
    
    
    d = "01/12/19"
    
    Set rFind = Range("A:A").Find(What:=d, SearchDirection:=xlPrevious)
    
    If Not rFind Is Nothing Then
        'insert row below found cell
        [COLOR=#ff0000][B]rFind.Offset(1).Rows.Insert[/B][/COLOR]
    Else
        MsgBox "Not Found"
    End If
    
    
End Sub
 
Upvote 0

Forum statistics

Threads
1,215,046
Messages
6,122,852
Members
449,096
Latest member
Erald

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