Loading
Ozgrid Excel Help & Best Practices Forums

Excel Video Tutorials / Excel Dashboards Reports



Results 1 to 3 of 3

Thread: Vertically Center Text In Userform Label

  1. #1
    Join Date
    4th January 2008
    Posts
    75

    Vertically Center Text In Userform Label

    Is it possible to vertically center the text in a userform label?

    For example: I have a label that's 22px high, but the text is only 10pt -- at the moment it just hangs out at the top of label looking bad.... I'd like to place it the middle if possible.

    thanks,
    eric

    Excel Video Tutorials / Excel Dashboards Reports


  2. #2
    Join Date
    7th March 2003
    Location
    Essex, England
    Posts
    11,310

    Re: Vertically Center Text In Userform Label

    The label control has no built in vertical alignment.
    The simplest way is to use 2 labels. One displays the border at the required size.
    The other is autosize to fit display text and then centered over the other label.

    This code assume 2 labels on a userform
    Label1 formatted to size of holding border.
    Label2 to hold text and center both vertically and horizontally.

    VB:
    With Label2 
        .AutoSize = False 
        .Height = 100 
        .Width = 200 
        .Caption = "This is my" & vbLf & "label text" 
        .AutoSize = True 
        .Top = Label1.Top + ((Label1.Height - .Height) / 2) 
        .Left = Label1.Left + ((Label1.Width - .Width) / 2) 
    End With 
    
    

    Cheers
    Andy


  3. #3
    Join Date
    4th January 2008
    Posts
    75

    Re: Vertically Center Text In Userform Label

    ah yes..... very sneaky! thanks andy!

    Excel Video Tutorials / Excel Dashboards Reports


Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Possible Answers

  1. Align & Center Text In Cells Vertically
    By Hayden Fox in forum EXCEL HELP
    Replies: 3
    Last Post: February 22nd, 2008, 00:58
  2. Center Down Selection Vertically
    By Dom01 in forum EXCEL HELP
    Replies: 7
    Last Post: October 15th, 2007, 07:29
  3. Replies: 2
    Last Post: February 15th, 2005, 09:04
  4. UserForm: Label Text Justification
    By excelboy in forum EXCEL HELP
    Replies: 3
    Last Post: July 13th, 2004, 02:58
  5. Center Text In label
    By sal21 in forum EXCEL HELP
    Replies: 10
    Last Post: June 25th, 2004, 00:50

Bookmarks

Posting Permissions

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