Command button code like userform.show

ipbr21054

Well-known Member
Joined
Nov 16, 2010
Messages
5,738
Office Version
  1. 2007
Platform
  1. Windows
Evening.
I am using the code below.
After i have been told that the item exists or does not exist i click on OK and the message box closes.
I then need to click again on the command button3 to show me the box & type in another number.

What i would like is to be able to apply something like userform.show code so it opens again without me doing it each time.
The also have the option to close it manually myself once finished.


Code:
Private Sub CommandButton3_Click()'Modified  10/14/2018  8:12:52 AM  EDT
Application.ScreenUpdating = False
Dim ans As String
Dim rr As Long
Dim LastRow As Long
LastRow = Cells(Rows.Count, "A").End(xlUp).Row
ans = InputBox("Enter search for value")
Set SearchRange = Range("A3:A" & LastRow).Find(ans)
If SearchRange Is Nothing Then MsgBox "The Part Number " & ans & " Is Not In The List", vbCritical: Exit Sub
rr = SearchRange.Row
MsgBox "The Part Number  " & ans & "  Can Be Found In Row  " & rr, vbExclamation
Application.ScreenUpdating = False
End Sub
 
I think what we are missing from the code below is the second line which is the question.

Ive tried a few times but keep getting a syntax error

Code:
[COLOR=#333333][I]If MsgBox("The Part Number  " & ans & "  Can Be Found In Row  " & Fnd.Row, vbYesNo) = vbYes Then Set Fnd = Nothing Else Exit Sub[/I][/COLOR]
 
Upvote 0

Excel Facts

Copy a format multiple times
Select a formatted range. Double-click the Format Painter (left side of Home tab). You can paste formatting multiple times. Esc to stop
All you need to do is add it in, in the sameway as it is on the previous msgbox.
 
Upvote 0
I tried a few time but keep[ getting a syntax error.

I have it like this at present

Code:
If MsgBox("The Part Number  " & ans & "  Can Be Found In Row  " & Fnd.Row, vbLf & vbLf & "Search For Another", vbYesNo) = vbYes Then Set Fnd = Nothing Else Exit Sub
 
Upvote 0
Fluff,
I also see an issue with its search as its looking for partial numbers also.

If in cell 55 i have the number 123456 and i the search box i type 12 or 56 i am told it can be found in row 55
I think we need to look at a 100% match
 
Upvote 0
Fluff,
That now works great.

Looking at post #6 do you see why when i use it i get a syntax error ?
Im sure its just a character , & ) etc but i dont see where the issue is.
 
Upvote 0
a) As there is no code in post#6 I'm surprised you get a syntax error ;)
b) If you are getting a syntax error why did you say "That now works great."
 
Upvote 0
Where did 6 come from,i meant 14 same thing ha ha.
Run time error 13 type mismatch


Anyway,here is what i have so far.

Code:
Private Sub CommandButton3_Click()   Dim ans As String
   Dim Fnd As Range
   Do Until Not Fnd Is Nothing
      ans = InputBox("Enter search for value")
      If ans = "" Then Exit Sub
      Set Fnd = Range("A:A").Find(ans, , , xlWhole, , , False, , False)
      If Fnd Is Nothing Then
         If MsgBox("The Part Number " & ans & " Is Not In The List" & vbLf & vbLf & "Do you want to try again", vbYesNo) = vbNo Then Exit Sub
      Else
         If MsgBox("The Part Number  " & ans & "  Can Be Found In Row  " & Fnd.Row, vbLf & vbLf & "Search For Another", vbYesNo) = vbYes Then Set Fnd = Nothing Else Exit Sub
      End If
   Loop
End Sub

That works great was in respect to the search which is now looking for a 100% match where as before it was partial.
 
Upvote 0

Forum statistics

Threads
1,223,911
Messages
6,175,323
Members
452,635
Latest member
laura12345

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