+ Reply to Thread
Results 1 to 10 of 10

VBA to change cell alignment

  1. #1
    Forum Contributor
    Join Date
    04-16-2014
    Location
    Witbank, SA
    MS-Off Ver
    Excel 2013
    Posts
    268

    VBA to change cell alignment

    hi,

    I have searched but have not found...please help.

    I would like the contents of cell C1, which happens to be numbers, to align left if cell A1=0, align centre if cell A1 =1 and align Right if cell A1 =2. I realize this must be terribly easy...thanx a lot for any help..


    I STILL CANNOT SEEM TO REPLY TO MY GOOD SAMARITANS...I HOPE YOU GUYS SEE THIS SOMEHOW

    THANX TO BURAN, RIORAN AND JOHN DAVIS. YOU HAVE ALL BEEN A GREAT HELP!!

    OKAY..LET ME BE SPECIFIC...I USED BURAN'S IDEA...WORKS GREAT..THANX A LOT!!
    Last edited by juriemagic; 10-07-2014 at 08:37 AM. Reason: replies fail

  2. #2
    Forum Contributor
    Join Date
    09-26-2014
    Location
    Moscow, Russia
    MS-Off Ver
    MSE 10, MSE 13
    Posts
    179

    Re: VBA to change cell alignment

    Hello!

    When do you expect for alignment to change? By button click or when any part of worksheet is changed?
    Best wishes and have a nice day!

  3. #3
    Forum Expert
    Join Date
    06-25-2009
    Location
    Sofia, Bulgaria, EU
    MS-Off Ver
    Excel 2003-2013
    Posts
    1,290

    Re: VBA to change cell alignment

    Something like this

    Please Login or Register  to view this content.
    Note that it will be aligned right for any value <> 0 or 1
    If you are pleased with a member's answer then use the Star icon to rate it.

  4. #4
    Forum Contributor
    Join Date
    09-26-2014
    Location
    Moscow, Russia
    MS-Off Ver
    MSE 10, MSE 13
    Posts
    179

    Re: VBA to change cell alignment

    I think combination of subroutines will do better =)

    If you have to change A1 manually - then it could be better not to rely on sheet events.
    Check buttons in the attachment, may be you will like it.

    Please Login or Register  to view this content.
    Attached Files Attached Files

  5. #5
    Forum Expert
    Join Date
    06-25-2009
    Location
    Sofia, Bulgaria, EU
    MS-Off Ver
    Excel 2003-2013
    Posts
    1,290

    Re: VBA to change cell alignment

    Quote Originally Posted by Rioran View Post
    If you have to change A1 manually - then it could be better not to rely on sheet events
    if user has to click a custom button, then the macro more or less is not necessary - you can click the RibbonX as well with the same effect. :-)

  6. #6
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: VBA to change cell alignment

    Maybe:

    Please Login or Register  to view this content.

  7. #7
    Forum Contributor
    Join Date
    09-26-2014
    Location
    Moscow, Russia
    MS-Off Ver
    MSE 10, MSE 13
    Posts
    179

    Re: VBA to change cell alignment

    Quote Originally Posted by buran View Post
    if user has to click a custom button, then the macro more or less is not necessary - you can click the RibbonX as well with the same effect. :-)
    Yes, but in case of my buttons we have 1 click economy - you don't need to care about selecting a target cell =)

  8. #8
    Forum Expert
    Join Date
    06-25-2009
    Location
    Sofia, Bulgaria, EU
    MS-Off Ver
    Excel 2003-2013
    Posts
    1,290

    Re: VBA to change cell alignment

    Quote Originally Posted by Rioran View Post
    Yes, but in case of my buttons we have 1 click economy - you don't need to care about selecting a target cell =)
    well if it's about click economy, using sheet event like I did is the ultimate winner here :-)

  9. #9
    Forum Contributor
    Join Date
    09-26-2014
    Location
    Moscow, Russia
    MS-Off Ver
    MSE 10, MSE 13
    Posts
    179

    Re: VBA to change cell alignment

    Quote Originally Posted by buran View Post
    well if it's about click economy, using sheet event like I did is the ultimate winner here :-)
    Congratulations, then! =) But if it were amount-of-steps-contest... Hm... Let me think... To select A1 cell, to type value you need and filanlly to hit the Enter button... 3 steps against single button click =)

    I think we have to wait for author to reveal his or her eternal wishes... Wow, stop, all of us are helpful - see the 1-st message.

  10. #10
    Forum Expert
    Join Date
    06-25-2009
    Location
    Sofia, Bulgaria, EU
    MS-Off Ver
    Excel 2003-2013
    Posts
    1,290

    Re: VBA to change cell alignment

    Quote Originally Posted by Rioran View Post
    Congratulations, then! =) But if it were amount-of-steps-contest... Hm... Let me think... To select A1 cell, to type value you need and filanlly to hit the Enter button... 3 steps against single button click =)

    I think we have to wait for author to reveal his or her eternal wishes... Wow, stop, all of us are helpful - see the 1-st message.
    No we are not in a amount of steps contest. It's not necessary that user has to change a1 manually. it could be some sort of formula there. That's the reason why using event is better - it's independent of the user and alignment is "always" as it is expected to be. In your case (no matter how A1 has changed) human factor is always present - e.g. user who simply forgets to click the button...
    anyway - I'm not going in so much trouble without reason or to "prove" which solution is better. There are no "wrong" solutions anyway. I think it's useful for the person who ask as well as the other users who may come to this thread searching for similar solution, because it shows the benefits of each approach.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Replies: 1
    Last Post: 02-02-2012, 11:32 AM
  2. Change alignment based on if cell is text or number.
    By Owompa in forum Excel General
    Replies: 4
    Last Post: 07-21-2011, 03:54 PM
  3. How to change the alignment of multiple cells
    By Raptors in forum Excel General
    Replies: 2
    Last Post: 09-01-2010, 06:29 PM
  4. change alignment
    By lyealain in forum Excel General
    Replies: 2
    Last Post: 11-07-2008, 04:40 AM
  5. Excel will not allow me to change alignment
    By zalcjm in forum Excel General
    Replies: 2
    Last Post: 07-06-2006, 02:55 AM

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1