Trying to find if cell in range is exact match for criteria

Jeddo

Board Regular
Joined
Jan 26, 2019
Messages
50
Office Version
  1. 2019
Platform
  1. Windows
New to VBA and still trying to learn. I have a code to look in a column range and find if there is a numeric match for the value in a text box. It is working except for the problem I am having which is the formula is not finding an exact match. Example: I enter the number 61 in the text box. There is no 61 in the column range, but there is a 610, which the formula is recognizing as 61. Any help would be appreciated.

Dim rngCust As Range

Set rngCust = ActiveWorkbook.Worksheets("Auction Items").Range("B5:B180").Find(what:=Me.txtItem)

If rngCust Is Nothing Then

MsgBox "Item number does not exist"
 

Excel Facts

Bring active cell back into view
Start at A1 and select to A9999 while writing a formula, you can't see A1 anymore. Press Ctrl+Backspace to bring active cell into view.
Try the following:


Code:
Dim rngCust As Range
    If IsNumeric(Me.txtItem) Then valor = Val(Me.txtItem) Else valor = Me.txtItem
    Set rngCust = ActiveWorkbook.Worksheets("Auction Items").Range("B5:B180").Find( _
        what:=valor, LookIn:=xlValues, lookat:=xlWhole)
    '
    If rngCust Is Nothing Then
        MsgBox "Item number does not exist"
    Else
        MsgBox "Value : " & Me.txtItem.Value
    End If
 
Upvote 0
Try the following:


Code:
Dim rngCust As Range
    If IsNumeric(Me.txtItem) Then valor = Val(Me.txtItem) Else valor = Me.txtItem
    Set rngCust = ActiveWorkbook.Worksheets("Auction Items").Range("B5:B180").Find( _
        what:=valor, LookIn:=xlValues, lookat:=xlWhole)
    '
    If rngCust Is Nothing Then
        MsgBox "Item number does not exist"
    Else
        MsgBox "Value : " & Me.txtItem.Value
    End If

Thanks, that seems to do the trick. Way more than I ever could have figured out on my own. Thanks again
 
Upvote 0
Thanks, that seems to do the trick. Way more than I ever could have figured out on my own. Thanks again


Tip:
You can read the documentation in office, just search in google excel find.method, and you can do it with any excel instructions.
 
Upvote 0

Forum statistics

Threads
1,223,703
Messages
6,173,977
Members
452,540
Latest member
haasro02

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