GO TO THE LAST DATA BASED ON 2 CELL DATA

wndncg

Board Regular
Joined
Mar 24, 2017
Messages
84
Office Version
  1. 2019
  2. 2016
  3. 2013
I have a working code just for 1 data but i need based on 2 data. ty mrexcel.

Dim Rng As Range
Set Rng = Range("A" & Rows.Count).End(xlUp).Offset(1)
Set wsCellVal = Sheets("TEMPLATE")
Set wsFIN = Sheets("FIN")
cv = wsCellVal.Range("E1")
Columns("A").Find(cv, After:=Rng, SearchOrder:=xlByRows, SearchDirection:=xlPrevious, MatchCase:=False, _
SearchFormat:=False).Select
Application.Wait (Now + TimeValue("00:00:01"))
'wsFIN.Activate
'Call INSERT_ROW_SPECIFIC
'ActiveCell.EntireRow.Insert
 
I downloaded your file and imported the sheet into my macro-enabled workbook and ran it. It works. I don't know what the problem could be.

Edit: For some (unknown to me) reason, you have to have TEMPLATE as the active sheet. Having either of the other 2 in view causes an error. Did you try running it with TEMPLATE as the active sheet?
 
Upvote 0

Excel Facts

Last used cell?
Press Ctrl+End to move to what Excel thinks is the last used cell.
I downloaded your file and imported the sheet into my macro-enabled workbook and ran it. It works. I don't know what the problem could be.
it just shows: "Search Complete" and its not moving to the last data.
 
Upvote 0
Okay, I see what was causing the error (that I got, not what you got). The .Select part at the very end. (I hardly ever use select in VBA. But when you want to select a range in a sheet, that sheet has to be the active sheet.) Make the following modification.
VBA Code:
    Dim i As Integer
    For i = UBound(s) To 0 Step -1
        If .Cells(s(i), "B").Value = .Range("A1").Value Then
            Sheets(sheetName).Select '*************************New line of code
            .Range("A" & s(i) & ":" & "G" & s(i)).Select
            ActiveWindow.Zoom = True
            Exit Sub
        End If
    Next i
End With

it just shows: "Search Complete" and its not moving to the last data.
Then as far as it's concerned, either there was no match of the date in E1 and/or none of the matches of E1 have the value of A1 to the right of the match in column B.
 
Upvote 0
This is the match it gave me when I ran it. (And I have it zoom in a little on the match too.):
Match.PNG


I hope one of the MVP's steps in and helps, because I'm clueless.
 
Upvote 0
Okay, I see what was causing the error (that I got, not what you got). The .Select part at the very end. (I hardly ever use select in VBA. But when you want to select a range in a sheet, that sheet has to be the active sheet.) Make the following modification.
VBA Code:
    Dim i As Integer
    For i = UBound(s) To 0 Step -1
        If .Cells(s(i), "B").Value = .Range("A1").Value Then
            Sheets(sheetName).Select '*************************New line of code
            .Range("A" & s(i) & ":" & "G" & s(i)).Select
            ActiveWindow.Zoom = True
            Exit Sub
        End If
    Next i
End With


Then as far as it's concerned, either there was no match of the date in E1 and/or none of the matches of E1 have the value of A1 to the right of the match in column B.
i will clear what i want to happen sir.

-The button is INSERT DM
-INSERT DM will run based on:
1. A1 that will find the last data based on E1
2. So in theory when user pressed the button the selection will go A6

i hope it clears sorry for bad engrish.
1663569923195.png
 
Upvote 0
If you have a button to run it, then you need to assign the button to the sub named:
VBA Code:
Test__Find_Latest_Date
(No parameters.)

But just in case (for others), here is the xl2bb capture:
Book1
ABCDE
110000023061/1/20222/1/2022
2DUE Month(BP Office) AgencyName of AgencyAgency TypePS
31/1/20221000002306TESTTEST2671069.27
41/1/20221000002306TESTTEST2671069.27
51/1/20221000002306TESTTEST2671069.27
61/1/20221000002306TESTTEST2671069.27
72/1/20221000002306TESTTEST2671069.27
82/1/20221000002306TESTTEST2671069.27
92/1/20221000002306TESTTEST2671069.27
102/1/20221000002306TESTTEST2671069.27
112/1/20221000002306TESTTEST2671069.27
122/1/20221000002306FEB222FEB2222671069.27
132/1/20221000002306FEB222FEB2222671069.27
TEMPLATE
 
Upvote 0
i will clear what i want to happen sir.

-The button is INSERT DM
-INSERT DM will run based on:
1. A1 that will find the last data based on E1
2. So in theory when user pressed the button the selection will go A6

i hope it clears sorry for bad engrish.
That's exactly what it does.
 
Upvote 0
This has quite an overlap with your other thread.
If the code in the other thread is working, doesn't that mean that this part is no longer an issue ?
 
Upvote 0
This has quite an overlap with your other thread.
If the code in the other thread is working, doesn't that mean that this part is no longer an issue ?
Its different because it now wants to find the last data if based on 2 cell value
 
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