Move Objects on Userform Control

ravvio31

New Member
Joined
Feb 22, 2018
Messages
2
Im trying hard to find a solution to move a Frame to a defined place in my vba Userform. I actually want to hide/unhide objects which works well but as soon as an object is hidden the space is left BLANK. I want to make sure that there's no blank space on my userform and i would like to replace the blank space with .
I know the exact position on my userform where it should be placed.

I googled and found object has .Move property which can be used to do this. I tried this but my object disappears rather than moving.

I have an alternative of creating 3 types of forms and use the when needed but i want to move it to the right place and then auto-adjust the form (i have applied the macro already for auto-adjusting).

Please help me here. :confused:

My Macro code below :-
Private Sub UserForm_Activate()


If Sheets("Form").Range("F11").Value = 1 Then


Me.Frame2.Visible = False
Me.Frame1.Move Left:=0, Top:=1, Width:=0, Height:=0


ElseIf Sheets("Form").Range("E11").Value = 1 Then


Me.Frame1.Visible = False
Me.Frame2.Move Left:=0, Top:=0, Width:=0, Height:=0


ElseIf Sheets("Form").Range("E11").Value = 1 And Sheets("Form").Range("F11").Value = 1 Then


Me.Frame1.Visible = True
Me.Frame2.Visible = True


End If


Call CheckSize


End Sub


Private Sub CheckSize()
Dim h, w
Dim c As Control


h = 0: w = 0
For Each c In Me.Controls
If c.Visible Then
If c.Top + c.Height > h Then h = c.Top + c.Height
If c.Left + c.Width > w Then w = c.Left + c.Width
End If
Next c


If h > 0 And w > 0 Then
With Me
.Width = w + 40
.Height = h + 40
End With
End If
End Sub
 

Excel Facts

Shade all formula cells
To shade all formula cells: Home, Find & Select, Formulas to select all formulas. Then apply a light fill color.

Forum statistics

Threads
1,223,903
Messages
6,175,289
Members
452,631
Latest member
a_potato

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