+ Reply to Thread
Results 1 to 5 of 5

Cell Alignment based on another cell value

Hybrid View

  1. #1
    Registered User
    Join Date
    02-07-2011
    Location
    England
    MS-Off Ver
    Excel 2013
    Posts
    42

    Question Cell Alignment based on another cell value

    I was wondering if it was possible to align a cell based on the value within another cell.

    For Example:

    IF Cell A1=>1 AND <= 2 then align Cell B1 left

    IF Cell A1=>3 AND <= 4 then align Cell B1 centre

    IF Cell A1=>5 AND <= 6 then align Cell B1 Right

    I would also want this macro to activate on any change in Cell A1.

    Thanks for any help you can provide.

    Kind Regards
    E

  2. #2
    Forum Expert
    Join Date
    07-31-2010
    Location
    California
    MS-Off Ver
    Excel 2007
    Posts
    4,070

    Re: Cell Alignment based on another cell value

    Private Sub Worksheet_Change(ByVal Target As Range)
    
    If Target.Address = Range("A1").Address Then
        If Range("A1") >= 1 And Range("B1") <= 2 Then Range("B1").HorizontalAlignment = xlLeft
        If Range("A1") >= 3 And Range("B1") <= 4 Then Range("B1").HorizontalAlignment = xlCenter
        If Range("A1") >= 5 And Range("B1") <= 6 Then Range("B1").HorizontalAlignment = xlRight
    End If
    
    End Sub

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

    Re: Cell Alignment based on another cell value

    Try this attachment Sheet1 and see if it does what you want.
    Attached Files Attached Files

  4. #4
    Registered User
    Join Date
    02-07-2011
    Location
    England
    MS-Off Ver
    Excel 2013
    Posts
    42

    Re: Cell Alignment based on another cell value

    stnkynts & JOHN H. DAVIS, thank you so much. Problem solved!!

    Cheers
    E

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

    Re: Cell Alignment based on another cell value

    You're welcome. Glad to help out and thanks for the feedback.

+ 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. cell text alignment
    By racudd in forum Excel General
    Replies: 4
    Last Post: 09-29-2006, 10:49 AM
  4. Excel cell alignment
    By Sarbjit9122 in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 07-07-2006, 07:35 PM
  5. Cell alignment centered
    By Simon Fischer in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 07-21-2005, 06:05 AM

Tags for this Thread

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