Userform labels

John Davis

Well-known Member
Joined
Sep 11, 2007
Messages
3,457
Hello All:

I have a UserForm and what I'm trying too do is change the color property of all the labels on the form simultaneously. Any advice/ideas would be appreciated.
 

Excel Facts

Round to nearest half hour?
Use =MROUND(A2,"0:30") to round to nearest half hour. Use =CEILING(A2,"0:30") to round to next half hour.
Hi,

Is it a one-time-only procedure or do you want to automated this in code?

In that case, I would tag all the labels with a distinctive tag (e.g. 'lblcolor'), and create a loop where all the controls with the tag 'lblcolor' are altered.

HTH
 
Upvote 0
Hi,

Is it a one-time-only procedure or do you want to automated this in code?

In that case, I would tag all the labels with a distinctive tag (e.g. 'lblcolor'), and create a loop where all the controls with the tag 'lblcolor' are altered.

HTH

Thanks for your reply. I'd like too automate this in code. No sure about how too achieve what you are suggesting. I'm still in the learning process when it comes too code.
 
Upvote 0
Hi,

Well, I used that trick with an Access form, you can find the discussion about this here.

The Access-code was:
Code:
Dim ctl as Object

For Each ctl in Me.Controls
    If ctl.Tag = "Lockdown" Then
     Me(ctl.Name).Enabled = False   
   End if
Next ctl

NB: I'm not sure wheter this would work in Excel. I'm going to try it out...
 
Upvote 0
John,

I've a got working sample. Code:
Code:
Dim ctl As Object
  
    For Each ctl In Me.Controls
        If ctl.Tag = "lblcolor" Then
         Me(ctl.Name).BackColor = 255
       End If
    Next ctl

Place this behind a button (..) on your form and all the labels tagged with 'lblcolor' are going red (255).

I wanted to attach a document, but I can't figure out how I can do that here (newby on this forum).

HTH
 
Upvote 0
John,

I've a got working sample. Code:
Code:
Dim ctl As Object
  
    For Each ctl In Me.Controls
        If ctl.Tag = "lblcolor" Then
         Me(ctl.Name).BackColor = 255
       End If
    Next ctl

Place this behind a button (..) on your form and all the labels tagged with 'lblcolor' are going red (255).

I wanted to attach a document, but I can't figure out how I can do that here (newby on this forum).

HTH

Willem: Thanks for helping. Here is the code I'm working with.

Private Sub cmdUnflagged_Click()
Dim startcolor As Long
Dim lbl As Object
startcolor = Me.BackColor
For Each lbl In Me.Controls
If lbl.Tag = "lblcolor" Then
Me.BackColor = RGB(255, 0, 0)
End If
Next lbl
MsgBox ("Please wait while the form is -processing")
Call macReconUnflagged
Me.BackColor = startcolor
For Each lbl In Me.Controls
If lbl.Tag = "lblcolor" Then
Me.BackColor = startcolor
End If
Next lbl
MsgBox ("Processing is complete you may continue")
Windows("AGFA DRAWBACK UTILITY.xls").Activate
End Sub

I tried to incorporate what you suggested. However, the form color changes too Red on the click command, but the labels remain at the startcolor. I tagged everything "lblcolor". What I'm I doing wrong?
 
Upvote 0
Change:

Me.BackColor

to:

Me(lbl.Name).BackColor = 255

(and I hope you only tagged the labels)
 
Upvote 0
If you want to do all labels, you could just use:
Code:
    Dim ctl As MSForms.Control
    For Each ctl In Me.Controls
        If TypeOf ctl Is MSForms.Label Then ctl.BackColor = RGB(255, 0, 0)
    Next ctl
 
Upvote 0
Change:

Me.BackColor

to:

Me(lbl.Name).BackColor = 255

(and I hope you only tagged the labels)


That gets it for all the labels. I wanted the Forms background color too change as well. Now I'm getting the opposite of what I was getting previously.
 
Upvote 0
That gets it for all the labels. I wanted the Forms background color too change as well. Now I'm getting the opposite of what I was getting previously.

Well then, add
Code:
Me.BackColor = 255
to the code as well, and you're all set! :)
 
Upvote 0

Forum statistics

Threads
1,214,518
Messages
6,119,985
Members
448,935
Latest member
ijat

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