Display msgbox with lastrow input

RvdV16681

Board Regular
Joined
Mar 31, 2016
Messages
62
Hello,

I have a userform with a search button. What I would like is a msgbox popup with lastrow input equal to Textbox7.value.
I already have this code for looking up lastrow input that is equal to Textbox7.Value

Private Sub CommandButton6_Click()
Dim I As Long
Dim Lastrow As Long
Lastrow = Sheets("Blad1").Cells(Rows.Count, "A").End(xlUp).row
For I = Lastrow To 1 Step -1
If Sheets("Blad1").Cells(I, 1).value = TextBox7.value Then
MsgBox "Last used by: " & (Sheets("Blad1").Cells(I, 2).value) & vbNewLine & "Expected return date: " & (Sheets("Blad1").Cells(I, 6).value)
Exit Sub
End If
Next

End Sub

The next step before the msgbox is displayed, is that there has to be a value in column 4 on the same row from the last input as well. If that cell is empty the msgbox does not have to popup. Is it possible to add this to the code I already have?

Thanks in advance!!
 

Excel Facts

Repeat Last Command
Pressing F4 adds dollar signs when editing a formula. When not editing, F4 repeats last command.
Hi,
just a guess but see if below does what you want


Code:
Private Sub CommandButton6_Click()
    Dim I As Long
    Dim Lastrow As Long
    
    With Sheets("Blad1")
        Lastrow = .Cells(.Rows.Count, "A").End(xlUp).Row
        For I = Lastrow To 1 Step -1
            If .Cells(I, 1).Value = TextBox7.Value And Len(.Cells(I, 4).Value) > 0 Then
                MsgBox "Last used by: " & .Cells(I, 2).Value & vbNewLine & _
                "Expected return date: " & .Cells(I, 6).Value
                Exit Sub
            End If
        Next I
    End With
        
End Sub

Dave
 
Upvote 0
Hello Dave,

The code does not work, it gives a msgbox popup on every entry that is equal to Textbox7.value, I have the idea that the code does not look if cell 4 on the same last row has a value or not.
 
Upvote 0

Forum statistics

Threads
1,215,680
Messages
6,126,188
Members
449,296
Latest member
tinneytwin

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