If userform textbox contains a value then...

Mikeymike_W

Board Regular
Joined
Feb 25, 2016
Messages
171
Hi, I am trying to make a label visible/invisible depending on the partial value of a textbox in a userform.
So the text box will contain lots of different text but if it contains Top of the card or bottom of the card etc then i want te label to be visible otherwise i want the label to be invisible.
This is what I have been trying but the label is always visible:
VBA Code:
If TBRandA.Text <> "The top of the Card" Then
LblInfo1.Visible = True
ElseIf TBRandA.Text <> "The bottom of the Card" Then
LblInfo1.Visible = True
ElseIf TBRandA.Text <> "The left of the Card" Then
LblInfo1.Visible = True
ElseIf TBRandA.Text <> "The right of the Card" Then
LblInfo1.Visible = True
Else
LblInfo1.Visible = False
End If

Many thanks in advance for your help,

Mike
 

Excel Facts

Who is Mr Spreadsheet?
Author John Walkenbach was Mr Spreadsheet until his retirement in June 2019.
This is not case sensitive
LblInfo1 is rendered non visible unless TBRandA contains one of those 4 phrases

VBA Code:
    Dim a As Variant, Txt As String
    LblInfo1.Visible = False
    For Each a In Array("top", "bottom", "left", "right")
        Txt = "the " & a & " of the card"
        If InStr(1, TBRandA.text, Txt, vbTextCompare) Then LblInfo1.Visible = True
    Next
 
Upvote 0
This is not case sensitive
LblInfo1 is rendered non visible unless TBRandA contains one of those 4 phrases

VBA Code:
    Dim a As Variant, Txt As String
    LblInfo1.Visible = False
    For Each a In Array("top", "bottom", "left", "right")
        Txt = "the " & a & " of the card"
        If InStr(1, TBRandA.text, Txt, vbTextCompare) Then LblInfo1.Visible = True
    Next
Yongle thank you so much, that worked a treat!
 
Upvote 0

Forum statistics

Threads
1,223,099
Messages
6,170,107
Members
452,302
Latest member
TaMere

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