Control Userform labels and buttons with VB macro

Nitehawkhp

New Member
Joined
Dec 2, 2016
Messages
37
Hello,

I'm trying to control various labels on a Userform.
Some of the things I want control:

Change color of a button based on whether it has been clicked

Is it possible to make a button visible or invisible by a macro?
I have tried to use the following to accomplish this:

Code:
Label56.visible = "False" and
Label56.visible = "True"

However, it doesn't seem to do anything. The label remains visible in all cases.

Is it possible to use a OptionButton as an indicator i.e. "Active" or "Not Active"

Rod
 
Upvote 0

Excel Facts

Excel Can Read to You
Customize Quick Access Toolbar. From All Commands, add Speak Cells or Speak Cells on Enter to QAT. Select cells. Press Speak Cells.
Have you tried Norie's suggestion from post#10?

Also which labels/buttons are you trying to hide?
 
Upvote 0
Try this as the forms' Initialize event code (currently the last code on the form):

Code:
Private Sub UserForm_Initialize()

    Dim lngCounter2 As Long
    Dim MyLabel As String
    
    For lngCounter2 = 56 To 78
        MyLabel = "Label" & lngCounter2
        Controls(MyLabel).Visible = False
    Next lngCounter2

End Sub
 
Upvote 0
I can't try any of the suggestions.
Everytime I try and display the userform I get:

Run-time error '434':

Object required

I tried to put the excel file on the google drive so everyone here could see what was going on.

I going crazy. It was working fine and then it stopped.
 
Upvote 0
Your form opens quite happily for me.
In the Vb Editor click on Tools > Options > General > and check "Break in class module" > Ok
The try to open the userform, what error do you get & what line of code is highlighted when you click debug?
 
Upvote 0
I downloaded the file and the code I posted worked.
 
Upvote 0
Your form opens quite happily for me.
In the Vb Editor click on Tools > Options > General > and check "Break in class module" > Ok
The try to open the userform, what error do you get & what line of code is highlighted when you click debug?

Fluff,

The reason my userform would not display is because of this code.
It fails on the line in BOLD.

Code:
Private Sub UserForm_Initialize()


    Dim lngCounter2 As Long
    Dim Label, MyLabel As String
        For lngCounter2 = 56 To 78
            MyLabel = lngCounter2
            Label = Label & lngCounter2 'MyLabel ',lngCounter2.Visible = False
            [B]Label.Visible = False[/B]
        Next lngCounter2


End Sub
 
Upvote 0
Glad it's sorted & thanks for the feedback
 
Last edited:
Upvote 0

Forum statistics

Threads
1,223,227
Messages
6,170,849
Members
452,361
Latest member
d3ad3y3

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