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

Difference between two dates
Secret function! Use =DATEDIF(A2,B2,"Y")&" years"&=DATEDIF(A2,B2,"YM")&" months"&=DATEDIF(A2,B2,"MD")&" days"
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,224,822
Messages
6,181,165
Members
453,021
Latest member
Justyna P

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