Comparing a cell value to a text box value from a user form

otty_j

New Member
Joined
Feb 21, 2018
Messages
2
I am trying to compare the value in a cell to the value that I have entered into a user form text box. If the values match I am returning a vbOKOnly text box showing that the value in the text box is a duplicate of a cell on my sheet.

I have the following code:

if Sheet.Cells(Row, Column).value = InvoiceNumberTextBox.value Then

Where my Row and Column values are variables in a loop.

If the value in the cell has a letter in it (i.e. "A-123" or "A 123") everything works correctly. However, if there is not a letter in the cell value (i.e. "123") then it does not detect a match.

Any suggestions to how I should be doing this differently?
 

Excel Facts

Move date out one month or year
Use =EDATE(A2,1) for one month later. Use EDATE(A2,12) for one year later.
which way round is it struggling, is it worth trying round

if Sheet.Cells(Row, Column).value = InvoiceNumberTextBox.Text Then
 
Upvote 0
Thanks much Dryver. That appears to have fixed it...though I have no understanding of why. All I can find is that .value should return just the value that is in the cell and .text should return what is actually seen in the cell including formatting. I'm having a hard time figuring how a string of numbers is throwing this off...I've gone through and set all of the cell formatting to the default values and it still doesn't work with the .value. I did a little looking into it and have also come across a .Value2 which is returning a compiler error.

If anyone can enlighten me that would be great but it's working with the .text so thanks much!
 
Upvote 0

Forum statistics

Threads
1,215,059
Messages
6,122,913
Members
449,093
Latest member
dbomb1414

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