Getting an exact match in a search

Jeddo

Board Regular
Joined
Jan 26, 2019
Messages
50
Office Version
  1. 2019
Platform
  1. Windows
Hello, new to VBA, so forgive my ignorance.

I created a spreadsheet which I am adding data and assigning a number to the data. I have a search setup to make sure the number I am assigning is not already used. It works great except it cannot differentiate between say 75 and 175 or 1075, which is a problem I can't figure out how to get around

Here is my line of code:

Set rngCust = ActiveWorkbook.Worksheets("Auction Items").Range("B6:B240").Find(Me.txtAddItem)

If rngCust Is Nothing Then

How do I get it to do an exact match to me.txtAddItem?
 

Excel Facts

How to fill five years of quarters?
Type 1Q-2023 in a cell. Grab the fill handle and drag down or right. After 4Q-2023, Excel will jump to 1Q-2024. Dash can be any character.
Try this

Code:
Set rngCust = ActiveWorkbook.Worksheets("Auction Items").Range("B6:B240").Find(Me.txtAddItem, , xlvalues, xlwhole)

If the content of the textbox is a number and in the cells you also have numbers, then try:

Code:
Set rngCust = ActiveWorkbook.Worksheets("Auction Items").Range("B6:B240").Find(Val(Me.txtAddItem), , xlvalues, xlwhole)
 
Upvote 0
Try this

Code:
Set rngCust = ActiveWorkbook.Worksheets("Auction Items").Range("B6:B240").Find(Me.txtAddItem, , xlvalues, xlwhole)

If the content of the textbox is a number and in the cells you also have numbers, then try:

Code:
Set rngCust = ActiveWorkbook.Worksheets("Auction Items").Range("B6:B240").Find(Val(Me.txtAddItem), , xlvalues, xlwhole)



Many thanks sir. I tried the second line as I have only numbers in the textbox and the cells I am searching. Worked like a charm. Thanks for also keeping it simple for this novice.
 
Upvote 0

Forum statistics

Threads
1,223,702
Messages
6,173,951
Members
452,539
Latest member
delvey

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