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

What do {} around a formula in the formula bar mean?
{Formula} means the formula was entered using Ctrl+Shift+Enter signifying an old-style array formula.
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,224,749
Messages
6,180,725
Members
452,995
Latest member
isldboy

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