VBA Code to Center Data
Results 1 to 6 of 6

Thread: VBA Code to Center Data
Thanks Thanks: 0 Likes Likes: 0

  1. #1
    Board Regular
    Join Date
    Aug 2009
    Location
    The OC, where else?
    Posts
    1,281
    Post Thanks / Like
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    Default VBA Code to Center Data

    I am trying to center data in column A, C, D, and E with a macro. I am using the code below but the sort will not work so I am not sure what I did wrong. Can anyone help?

    Range("A2,C2:E2" & Cells(Rows.Count, "E").End(xlUp).Row)
    I am using the beautiful Excel 2016!

  2. #2
    MrExcel MVP
    Moderator
    Fluff's Avatar
    Join Date
    Jun 2014
    Location
    Chippenham
    Posts
    25,664
    Post Thanks / Like
    Mentioned
    445 Post(s)
    Tagged
    45 Thread(s)

    Default Re: VBA Code to Center Data

    How about
    Code:
       Range("A:E").EntireColumn.HorizontalAlignment = xlCenter
    - Posting Data try one of these tools
    - Posting guidelines, forum rules and terms of use
    - Read the FAQs

    Running Office 365 on Win 10

  3. #3
    Board Regular
    Join Date
    Aug 2009
    Location
    The OC, where else?
    Posts
    1,281
    Post Thanks / Like
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    Default Re: VBA Code to Center Data

    I am only centering A, C, D, and E, not A:E.
    I am using the beautiful Excel 2016!

  4. #4
    MrExcel MVP
    Moderator
    Fluff's Avatar
    Join Date
    Jun 2014
    Location
    Chippenham
    Posts
    25,664
    Post Thanks / Like
    Mentioned
    445 Post(s)
    Tagged
    45 Thread(s)

    Default Re: VBA Code to Center Data

    In that case
    Code:
       Range("A:A,C:E").EntireColumn.HorizontalAlignment = xlCenter
    - Posting Data try one of these tools
    - Posting guidelines, forum rules and terms of use
    - Read the FAQs

    Running Office 365 on Win 10

  5. #5
    Board Regular
    Join Date
    Aug 2009
    Location
    The OC, where else?
    Posts
    1,281
    Post Thanks / Like
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    Default Re: VBA Code to Center Data

    Thank you so much!
    I am using the beautiful Excel 2016!

  6. #6
    MrExcel MVP
    Moderator
    Fluff's Avatar
    Join Date
    Jun 2014
    Location
    Chippenham
    Posts
    25,664
    Post Thanks / Like
    Mentioned
    445 Post(s)
    Tagged
    45 Thread(s)

    Default Re: VBA Code to Center Data

    You're welcome
    - Posting Data try one of these tools
    - Posting guidelines, forum rules and terms of use
    - Read the FAQs

    Running Office 365 on Win 10

Some videos you may like

User Tag List

Tags for this Thread

Like this thread? Share it with others

Like this thread? Share it with others

Posting Permissions

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