aligning a userform

methody

Well-known Member
Joined
Jun 17, 2002
Messages
841
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
 

Some videos you may like

Excel Facts

Can you AutoAverage in Excel?
There is a drop-down next to the AutoSum symbol. Open the drop-down to choose AVERAGE, COUNT, MAX, or MIN

Tom Urtis

MrExcel MVP
Joined
Feb 10, 2002
Messages
11,224
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
 

Whisperer14

Well-known Member
Joined
Nov 6, 2002
Messages
589
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
 

Tom Urtis

MrExcel MVP
Joined
Feb 10, 2002
Messages
11,224

ADVERTISEMENT

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.
 

Whisperer14

Well-known Member
Joined
Nov 6, 2002
Messages
589
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
 

Tom Urtis

MrExcel MVP
Joined
Feb 10, 2002
Messages
11,224
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
 

Watch MrExcel Video

Forum statistics

Threads
1,122,519
Messages
5,596,635
Members
414,083
Latest member
Mrsash

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
Top