Highlighting Multiple Textbox in User Form

deeast

New Member
Joined
Jun 22, 2022
Messages
4
Office Version
  1. 2010
Platform
  1. Windows
it is possible to highlight multiple textbox in one userform to inform that the field need to be field?
VBA Code:

If TBPOCD.value = "" Or TBEPON.value = "" Or TBLN.value = "" Then
If TBPOCD.value = "" Then
TBPOCD.BackColor = vbYellow
Exit Sub
End If

If TBEPON.value = "" Then
TBEPON.BackColor = vbYellow
Exit Sub
End If

If TBLN.value = "" Then
TBLN.BackColor = vbYellow
End If
 

Excel Facts

Convert text numbers to real numbers
Select a column containing text numbers. Press Alt+D E F to quickly convert text to numbers. Faster than "Convert to Number"
it is possible to highlight multiple textbox in one userform to inform that the field need to be field?
VBA Code:

If TBPOCD.value = "" Or TBEPON.value = "" Or TBLN.value = "" Then
If TBPOCD.value = "" Then
TBPOCD.BackColor = vbYellow
Exit Sub
End If

If TBEPON.value = "" Then
TBEPON.BackColor = vbYellow
Exit Sub
End If

If TBLN.value = "" Then
TBLN.BackColor = vbYellow
End If
So, you want to search all the Textboxes in your Userform and if their value is nothing Turn The back color of them to Yellow is that what you want
 
Upvote 0
Try this:
VBA Code:
Private Sub CommandButton1_Click()
'Modified  6/22/2022  8:28:25 PM  EDT
For Each Xcontrol In Me.Controls
        If TypeName(Xcontrol) = "TextBox" Then
            If Xcontrol.Value = vbNullString Then
                Xcontrol.BackColor = vbYellow
            End If
        End If
    Next Xcontrol
End Sub
 
Upvote 0
Solution
Try this:
VBA Code:
Private Sub CommandButton1_Click()
'Modified  6/22/2022  8:28:25 PM  EDT
For Each Xcontrol In Me.Controls
        If TypeName(Xcontrol) = "TextBox" Then
            If Xcontrol.Value = vbNullString Then
                Xcontrol.BackColor = vbYellow
            End If
        End If
    Next Xcontrol
End Sub
i'm sorry Xcontrol set as what? I'm really new in this, TIA
 
Upvote 0
i'm sorry Xcontrol set as what? I'm really new in this, TIA
Did you try to run the script?

The xcontrol we are looking for are Textboxes in your userform.
The script looks for all Textboxes in your userform

Why is the script not working
Put my script in a button on the Userform
 
Upvote 0
You're using a very old version of Excel 2010
As I'm using 2013 which is also old, but the script works for me
 
Upvote 0
You're using a very old version of Excel 2010
As I'm using 2013 which is also old, but the script wits work

Did you try to run the script?

The xcontrol we are looking for are Textboxes in your userform.
The script looks for all Textboxes in your userform

Why is the script not working
Put my script in a button on the Userform
finally its work, yayy.. TIA
 
Upvote 0

Forum statistics

Threads
1,223,879
Messages
6,175,148
Members
452,615
Latest member
bogeys2birdies

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