Results 1 to 5 of 5
  1. #1
    3 Star Lounger
    Join Date
    Jan 2001
    Location
    Lewes, East Sussex, Sussex, United Kingdom
    Posts
    232
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Aligning controls on Userforms (Excel 2003 SP2)

    I have just come across a very annoying "feature" in Excel when positioning controls on a userform. I have various labels and associated text boxes, which I want to display the same vertical alignment, i.e. so that the text within both of them is on the same (imaginary) horizontal line.

    I have set the Height and Top properties for all the controls on the same line to be identical, and I would have expected them to look correctly aligned when the form opens. However the text in the textboxes ends up lower than the text in the labels.

    Is there an easy way around this, apart from manually aligning all the controls using the mouse. This is really annoying because it looks very poor, and is a pain to fix.

    Usual thanks for your help

    Nick

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Aligning controls on Userforms (Excel 2003 SP2)

    This has always been an annoyance in userforms, not just in Excel. The Top of labels has to be 3 points down from that of text boxes for the text to align.

    If you don't want to adjust the position of the labels manually, you could put code in the UserForm_Initialize event:

    Private Sub UserForm_Initialize()
    Dim ctl As Control
    For Each ctl In Me.Controls
    If TypeName(ctl) = "Label" Then
    ctl.Top = ctl.Top + 3
    End If
    Next ctl
    End Sub

  3. #3
    3 Star Lounger
    Join Date
    Jan 2001
    Location
    Lewes, East Sussex, Sussex, United Kingdom
    Posts
    232
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Aligning controls on Userforms (Excel 2003 SP2)

    Hans

    Thank you. As always, you are a mine of useful & practical information.

    When you want to make your fortune, just publish your book "Hans on Access and Excel". It will sell millions. <img src=/S/bingo.gif border=0 alt=bingo width=15 height=22>

    Nick

  4. #4
    WS Lounge VIP rory's Avatar
    Join Date
    Dec 2000
    Location
    Burwash, East Sussex, United Kingdom
    Posts
    6,280
    Thanks
    3
    Thanked 191 Times in 177 Posts

    Re: Aligning controls on Userforms (Excel 2003 SP2)

    You mean you haven't got a copy yet? <img src=/S/grin.gif border=0 alt=grin width=15 height=15>
    Regards,
    Rory

    Microsoft MVP - Excel

  5. #5
    3 Star Lounger
    Join Date
    Jan 2001
    Location
    Lewes, East Sussex, Sussex, United Kingdom
    Posts
    232
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Aligning controls on Userforms (Excel 2003 SP2)

    Just checked on Amazon & it's out of stock...as always

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •