Reconfigure Userform Layout based on IF statement

mharper90

Board Regular
Joined
May 28, 2013
Messages
117
Office Version
  1. 365
Platform
  1. MacOS
I have a UserForm that has several "extra" checkboxes. These checkboxes are enabled in some scenarios, but I use an IF statement to hide them most of the time, based on what is going on in the worksheet.

I have the checkboxes functioning properly, but because hiding them leaves a lot of empty space on the UserForm, I want to add to the same IF statement, to shift CommandButton1 & 2 up to a predetermined location (overtop of where the hidden checkboxes are hiding), and also to shorten the overall height of the UserForm by a similar amount.

I researched this a long time ago to see if it was possible, and now I can't figure out how to do it, and I can't find whatever I referenced on my first search. Thanks!
 

Excel Facts

Create a chart in one keystroke
Select the data and press Alt+F1 to insert a default chart. You can change the default chart to any chart type
I would think something like this would work.
Modify to your needs.
The script is activated when you click CheckBox4

Code:
Private Sub CheckBox4_Click()
'Modified  2/18/2019  10:38:41 PM  EST
Select Case CheckBox4.Value
Case True
    CheckBox1.Top = 10
    CheckBox2.Top = 10
    CheckBox3.Top = 10
    CommandButton1.Top = 20
    CommandButton2.Top = 20
 Case False
    CheckBox1.Top = 30
    CheckBox2.Top = 30
    CheckBox3.Top = 30
    CommandButton1.Top = 50
    CommandButton2.Top = 50
End Select
End Sub
 
Upvote 0
Or you could do it this way:
Put all your checkboxes and command buttons inside a Frame

And then when you click on checkbox5 which is not inside the frame
All the controls inside the Frame will be hidden.

Code:
Private Sub CheckBox5_Click()
'Modified  2/18/2019  10:56:32 PM  EST
Select Case CheckBox5.Value
Case True
    Frame1.Visible = False
Case False
 Frame1.Visible = True
End Select
End Sub
 
Upvote 0
If you have a lot of controls on a Userform and are limited to space and you want to make the userform larger and smaller from time to time.

Have you ever looked into Multipages

A workbook has several different worksheets as many as you want.

A Userform can have what looks like many Userforms

It's called a Multipage

So at times you can click on the Multipage Tab
And then you can see another what looks like Userform

Just like when you click on a sheet tab you see a different sheet.

So Your Multipage has what is called Multipage Pages

Click on The tab of the one you want to see.
Each Multipage Tab can have as many controls as you want just like the Userform can have many controls..

You may want to look into UserForm Multipages
 
Upvote 0
and also to shorten the overall height of the UserForm by a similar amount.
To set a userform height you can use something like this:

Code:
Me.Height = 200
 
Upvote 0

Forum statistics

Threads
1,223,231
Messages
6,170,885
Members
452,364
Latest member
springate

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