-
Shorten code
is there a better or shorter/efficient way of writing this code?
Code:
If msg1.Caption = "Airport Shuttle Tips*" Or msg2.Caption = "Airport Shuttle Tips*" Or _
msg3.Caption = "Airport Shuttle Tips*" Or msg4.Caption = "Airport Shuttle Tips*" Or _
msg5.Caption = "Airport Shuttle Tips*" Then LTips.Visible = True
-
Where do msg1, msg2, etc reside? Are the part of a user form, are they controls on a worksheet?
-
If they are on a user form you can use something like:
Code:
Dim i As Integer
For i = 1 To 5
If Me.Controls("msg" & i).Caption Like "Airport Shuttle Tips*" Then
LTips.Visible = True
End If
Next
-
Dunno about shorter, but better IMO
Code:
msgTest = "Airport Shuttle Tips*"
LTips.Visible = msg1.Caption = msgTest Or _
msg2.Caption = msgTest Or _
msg3.Caption = msgTest Or _
msg4.Caption = msgTest Or _
msg5.Caption = msgTest
-
Thank you both for your help. XLD, you have tremendously help me in the past, which I am always grateful, but mbarron's code is what I was looking for.:friends:
-
Personally, I would not use a loop for 5 items, but you have an answer, so that is good.