aligning a userform

methody

Well-known Member
Joined
Jun 17, 2002
Messages
857
Hello
Can anyone help. I am using a userform which opens in the middle of the sheet but this is covering material which I want to be visible when the userform is being filled in. Is there a way of automatically opening on the right of the page. I'd appreciate any help
Methody
 

Excel Facts

Last used cell?
Press Ctrl+End to move to what Excel thinks is the last used cell.
You can specify positioning at the Initialization event (when the userform is called), for example:

Private Sub UserForm_Initialize()
'Upper left
Me.StartUpPosition = 0
Dim Top As Double, Left As Double
Top = Abs(Application.Top) + (Application.Height - ActiveWindow.Height) + (Application.UsableHeight - ActiveWindow.UsableHeight)
Left = Abs(Application.Left) + ActiveWindow.Width - ActiveWindow.UsableWidth
Me.Top = Top
Me.Left = Left
End Sub


The other 3 corners would be:

'Upper right
Me.StartUpPosition = 0
Dim Top As Double, Left As Double
Top = Abs(Application.Top) + (Application.Height - ActiveWindow.Height) + (Application.UsableHeight - ActiveWindow.UsableHeight)
Left = Abs(Application.Left) + (Application.Width) - (Me.Width + 10)
Me.Top = Top
Me.Left = Left

'Lower left
Me.StartUpPosition = 0
Dim Top As Double, Left As Double
Top = Abs(Application.Top) + (Application.Height) - (Me.Height + 10)
Left = Abs(Application.Left) + ActiveWindow.Width - ActiveWindow.UsableWidth
Me.Top = Top
Me.Left = Left

'Lower right
Me.StartUpPosition = 0
Dim Top As Double, Left As Double
Top = Abs(Application.Top) + (Application.Height) - (Me.Height + 10)
Left = Abs(Application.Left) + (Application.Width) - (Me.Width + 10)
Me.Top = Top
Me.Left = Left
 
Upvote 0
Or you can set it manually by trial and error to any position on the screen.

In the properties for the Userform select the 'StartUpPosition' to 0-Manual,
then select the 'Left' to say 50 and the 'Top' to 200, experiment until you are happy with the position

HTH

Gordon
 
Upvote 0
Whisperer14 said:
Or you can set it manually by trial and error to any position on the screen.
That would only be a practical approach if you are the only one using the program and your screen resolution setting never changes. If you ever change your resolution, or other users use the program whose screen settings are (inevitably) different than yours, that manual setting approach would not fit the other screens.

Easier to just "set it and forget it" in code.
 
Upvote 0
Quite agree Tom,

so how about modifying your excellent code to give a position which is 50 inset from the right side of the page and in the middle of the useable height, taking into account the height and width of the userform.

(y) Gordon
 
Upvote 0
Try this:

Private Sub UserForm_Initialize()
Me.StartUpPosition = 0
Me.Top = (Application.Height - Me.Height) / 2
Me.Left = (Application.Width - Me.Width - 50)
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,620
Messages
6,120,559
Members
448,970
Latest member
kennimack

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