change toggle button value on userform open

drewbsking

New Member
Joined
Nov 3, 2011
Messages
34
I would like to set the value of a toggle button when the userform is opened so that it coincides with the what columns are hidden on screen. Below is simple example which I have not tested or debugged. It was just what i was thinking.

Does anyone have any suggestions? Mr. Users have been a GREAT help and I'm getting better and better at writing VBA code so thank you all in advance.

Code:
Sub Macro2()

'if col A is hidden
If Columns("A").EntireColumn.Hidden = True Then

'make hidecalcs toggle button true (sunken)

Userform1.HideCalcs.Value = True
Else

'make hadcalcs toggle button false (raised)
Userform1.HideCalcs.Value = False
End If

End Sub
 
You could do it in one line like this:
Code:
Private Sub UserForm_Initialize()
    Me.HideCalcs.Value = Sheets("Sheet1").Columns("A").Hidden
End Sub
 
Upvote 0
Great Tip. I just had to remember not to change "userform" to the name of the form. Changing that will result it not working but still not error out.
 
Upvote 0

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