Loading
Ozgrid Excel Help & Best Practices Forums

Excel Video Tutorials / Excel Dashboards Reports



Results 1 to 6 of 6

Thread: Text Alignment Of Entire Column In Vba

  1. #1
    Join Date
    15th May 2007
    Location
    TX, USA
    Posts
    28

    Text Alignment Of Entire Column In Vba

    I have run this code
    VB:
    For Each sheet In worksheets 
        sheet.Columns("A").ColumnWidth = 7.43 
        sheet.Columns("A").VerticalAlignment = xlVAlignTop 
        sheet.Columns("A").HorizontalAlignment = xlHAlignRight 
    Next 
    
    
    But when I go to format cell & look at the text alignment it is still general & bottom.

    Any Ideas??
    Thanks, Chuck

    Excel Video Tutorials / Excel Dashboards Reports


  2. #2
    Join Date
    23rd April 2007
    Posts
    3,486

    Re: Text Alignment Of Entire Column In Vba

    The variable sheet has an unfortunate name. It's close to a VB term, which may be the cause of your problem. Substituting another name might set things right. If that doesn't work, I'd try qualifying the columns with .Cells as in
    VB:
    xShet.Columns("A").Cells.HorizontalAlignment = xlHAlignRight 
    
    
    Also, if you have two workbooks open, it might be confused as to which worksheets to cycle through.
    (That's odd, if you copy/pasted that code from your VB editor, worksheets should be capitalized. When that kind of thing happens to me, deleting and retyping a letter usualy wakes Excel up.)
    Last edited by mikerickson; June 5th, 2007 at 11:49.

    Excel Video Tutorials / Excel Dashboards Reports


  3. #3
    Join Date
    15th May 2007
    Location
    TX, USA
    Posts
    28

    Re: Text Alignment Of Entire Column In Vba

    Miike,

    Thanks, the .cells did the trick. I will change the name but it did work without changing it.

    Chuck

    Excel Video Tutorials / Excel Dashboards Reports


  4. #4
    Join Date
    23rd April 2007
    Posts
    3,486

    Re: Text Alignment Of Entire Column In Vba

    "sheet" isn't a reserved word, but its close enough that I had to look at the Object Browser to remind myself that it wasn't.

    Glad it worked out.

    Excel Video Tutorials / Excel Dashboards Reports


  5. #5
    Join Date
    2nd January 2007
    Posts
    5

    Re: Text Alignment Of Entire Column In Vba

    You can try this aswell :
    VB:
    For i = 1 To Worksheets.Count 
        Worksheets(i).Activate 
        ActiveSheet.Columns("A").ColumnWidth = 7.43 
        ActiveSheet.Columns("A").VerticalAlignment = xlVAlignTop 
        ActiveSheet.Columns("A").HorizontalAlignment = xlHAlignRight 
    Next 
    
    




    Quote Originally Posted by chucktx
    I have run this code
    VB:
    For Each sheet In worksheets 
        sheet.Columns("A").ColumnWidth = 7.43 
        sheet.Columns("A").VerticalAlignment = xlVAlignTop 
        sheet.Columns("A").HorizontalAlignment = xlHAlignRight 
    Next 
    
    
    But when I go to format cell & look at the text alignment it is still general & bottom.

    Any Ideas??
    Thanks, Chuck
    Last edited by ByTheCringe2; June 6th, 2007 at 15:56.

    Excel Video Tutorials / Excel Dashboards Reports


  6. #6
    Join Date
    7th December 2005
    Location
    Hampshire, England
    Posts
    4,898

    Re: Text Alignment Of Entire Column In Vba

    niket1981, Welcome to the forum. However please read the rules and use code tags for VBA. I have added them for you this time, but normally the post would be deleted.
    .

Thread Information

Users Browsing this Thread

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

Possible Answers

  1. Replies: 20
    Last Post: September 25th, 2013, 00:51
  2. Maintaining Text Alignment When Uploading
    By KjBox in forum EXCEL HELP
    Replies: 3
    Last Post: March 27th, 2007, 02:12
  3. Load TextBox Column Alignment
    By minitman in forum EXCEL HELP
    Replies: 3
    Last Post: December 23rd, 2005, 21:20
  4. Replies: 2
    Last Post: October 19th, 2005, 22:30
  5. Excel Column Alignment Through Access
    By Lol999 in forum EXCEL HELP
    Replies: 14
    Last Post: April 10th, 2005, 20:09

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