Looking up a "banned" item from a Userform with VBA lockup

Grizlore

Active Member
Joined
Aug 22, 2006
Messages
259
I am looking for some help please, I am sure it is something simple.

When I enter a numerical value into the Userform textbox "txtRTAs" I would like it to look at a worksheet to see if the number is there. IF it is, then I want a simple MsgBox to inform that this number is there and "banned"

The code works for letters, but not for numberical values. I guess it is something simple, but it is rather frustrating as I cant fathom it out.

Any help would be greatly appreciated! The code below is the small section which isn't working

VBA Code:
Sub IsItBANNED()

Dim LookUpIfBanned 'as I have tried several


LookUpIfBanned = txtRTAs


If Not IsError(Application.VLookup(txtRTAs, Worksheets("banned").Range("TheseAreBanned"), 2, False)) Then
MsgBox "this is banned", vbCritical, "BANNED ALERT"

End If


End Sub
 

Excel Facts

What does custom number format of ;;; mean?
Three semi-colons will hide the value in the cell. Although most people use white font instead.
The problem is that the value in a text box is always a String. It needs to be converted to a number for VLOOKUP to work properly.

VBA Code:
Dim LookUpIfBanned as Variant

LookUpIfBanned = txtRTAs.Text

If IsNumeric(LookUpIfBanned) Then LookUpIfBanned = CDbl(LookUpIfBanned)

If Not IsError(Application.VLookup(LookUpIfBanned, Worksheets("banned").Range("TheseAreBanned"), 2, False)) Then

'etc

End If
 
Upvote 0
Solution
MANY THANKS

works like a dream... and now I can go to bed

I appreciate your time and help
 
Upvote 0

Forum statistics

Threads
1,223,897
Messages
6,175,270
Members
452,628
Latest member
dd2

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