adjusting function using mixed character instead of numeric when search item

MKLAQ

Active Member
Joined
Jan 30, 2021
Messages
397
Office Version
  1. 2016
Platform
  1. Windows
hello
I 've found this thread VBA- Using search message box
and update by Dave .
VBA Code:
Sub CommandButton2_Click()
Dim Search          As Variant
Dim c               As Range
Dim sh              As Worksheet
Dim Response        As VbMsgBoxResult
    
Dim msg             As String, FirstAddress As String
Dim Prompts(1 To 2) As String, Prompt As String
    
Prompts(1) = "Serial number found On row(s) " & Chr(10) & Chr(10)
Prompts(2) = "Serial number Not found" & Chr(10) & Chr(10)
    
Set sh = ThisWorkbook.Worksheets("Sheet2")
    
Do
'display inputbox
Do
Search = InputBox("Enter Search Number Value:", "Search")
'cancel pressed
If StrPtr(Search) = 0 Then Exit Sub
Loop Until IsNumeric(Search)
        
Set c = sh.Columns(6).Find(What:=CLng(Search), LookIn:=xlValues, LookAt:=xlWhole, _
SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=True, SearchFormat:=False)
If Not c Is Nothing Then
FirstAddress = c.Address
msg = Prompts(1)
Do
msg = msg & c.Row & Chr(10)
Set c = sh.Columns(6).FindNext(c)
If c Is Nothing Then Exit Do
Loop Until FirstAddress = c.Address
Else
msg = Prompts(2) & Search & Chr(10)
End If
        
Response = MsgBox(msg & Chr(10) & "Do you want To make another search?", 36, "Results")
msg = ""
Loop Until Response = vbNo
    
End Sub
and see this is useful for me , but when search the item in column B should be the whole item is number , but in my case there are many items contains letters and numbers and symbols the code doesn't deal with non numeric items . how can I mod by using function deal with mixed character,please?
 

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.
Hi,
try making changes shown

Rich (BB code):
Do
Search = InputBox("Enter Search Value:", "Search")
'cancel pressed
If StrPtr(Search) = 0 Then Exit Sub
Loop Until Len(Search) > 0

If IsNumeric(Search) Then Search = Val(Search)
     
Set c = sh.Columns(6).Find(What:=Search, LookIn:=xlValues, LookAt:=xlWhole, _
SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=True, SearchFormat:=False)

Dave
 
Upvote 0
Solution
thanks for fast answering !
much appreciated for new updating (y)
 
Upvote 0
most welcome & appreciate feedback

Dave
 
Upvote 0

Forum statistics

Threads
1,215,076
Messages
6,122,987
Members
449,093
Latest member
Mr Hughes

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