How to Apply Alignment in Excel Conditional Formatting

To demonstrate alignment using conditional formatting, we have a sample data table like the image below.

A sample data table: How to Apply Alignment in Excel Conditional Formatting


Method 1 – Apply Right and Left Alignment for Text That Meets a Criteria

In Excel, the default text alignment is left alignment. In this method, we will see that any cell that meets a certain criterion will change its alignment.

Number Format for Right Aligned Text:

#,##0* ;;;* @

Steps:

  • Select the Color column, then go to Home and select Conditional Formatting, then select New Rule.

Apply Right and Left Alignment for Text That Meets a Criteria

  • The New Formatting Rule pop-up will appear like the image below.

 New Formatting Rule pop-up will appear

  • Select Use a formula to determine which cells to format.
  • Enter the following formula in the box of Format values where this formula is true:
=$C5="Blue"
  • Select Format.

Enter a formula in the box of Format values where this formula is true:

  • The Format Cells pop-up will appear.

Format Cells pop-up will appear

  • Go to Custom under the Number tab.
  • Enter the following formula:
#,##0* ;;;* @
  • Click OK.

Apply Right and Left Alignment for Text That Meets a Criteria

  • In New Formatting Rule, hit the OK.

Again in the New Formatting Rule, we will hit the OK

  • Blue has changed its alignment from left to right using conditional formatting.

Blue has changed its alignment from left to right


Method 2 – Align Numbers to Right, Center, and Left with Excel Conditional Formatting

The default number alignment in Excel is the right alignment. In this procedure, each cell that fulfills a given set of criteria will have its alignment changed.

For Center Alignment:

#,##0_)          ;(#,##0)          

For Left Alignment:

#,##0* ;;;* @

Steps:

  • Choose the Price column and select Conditional Formatting New Rule.

Align Numbers to Right, Center, and Left with Excel Conditional Formatting

  • Select Use a formula to determine which cells to format in New Formatting Rule.
  • Enter the following formula in the box for Format values where this formula is true:
=$D5>15
  • Press Format.

Press on Format

  • The Format Cells window will appear.

The Format Cells window will emerge

  • Select Custom from the Number menu in the Format Cells pop-up.
  • Plug in the following formula shown in the image below:
#,##0_)          ;(#,##0)          
  • Press OK.

Align Numbers to Right, Center, and Left with Excel Conditional Formatting

  • Select OK to complete the procedure.

we will select OK

  • The cells containing values more than 15 have aligned in the middle.

the result is in the following image

  • Select Use a formula to determine which cells to format in the New Formatting Rule pop-up.
  • Enter the following formula in the box of Format values where this formula is true:
=$D5>15
  • Choose Format.

Choose Format

  • The Format Cells pop-up will appear.

The Format Cells pop-up will appear

  • Select Custom from the Number menu in the Format Cells pop-up.
  • Plug in the following formula:
#,##0* ;;;* @
  • Press the OK button.

Align Numbers to Right, Center, and Left with Excel Conditional Formatting

  • Press the OK button in New Formatting Rule.

Press the OK button in the New Formatting Rule

  • Numbers bigger than 15 have been shifted from right to left utilizing conditional formatting.

Align Numbers to Right, Center, and Left with Excel Conditional Formatting

Note:

You can apply both rules and get the numbers in the left, middle, and right positions simultaneously.

Read More: How to Copy Conditional Formatting with Relative Cell References in Excel


Download the Practice Workbook


Related Articles

<< Go Back to Conditional Formatting | Learn Excel

Get FREE Advanced Excel Exercises with Solutions!
Al Ikram Amit
Al Ikram Amit

Al Ikram Amit, holding a BSc in Naval Architecture & Engineering from Bangladesh University of Engineering and Technology, serves as a key Excel & VBA Content Developer at ExcelDemy. Driven by a profound passion for research and innovation, he actively immerses himself in Excel. In his role, Amit not only skillfully addresses complex challenges but also exhibits enthusiasm and expertise in gracefully navigating tough situations, emphasizing his steadfast commitment to consistently delivering exceptional, high-quality content that adds significant... Read Full Bio

7 Comments
  1. Curious how this is accomplished if you want your number values to have 2 or more decimal places

    • Reply Abrar-ur-Rahman Niloy
      Abrar-ur-Rahman Niloy Jan 21, 2024 at 12:38 PM

      Hello Richard!

      You need to replace 0s in the format type with 0.00s.
      For example, instead of #,##0_) ;(#,##0) for center alignment, use #,##0.00_) ;(#,##0.00).

      Regards
      Niloy
      Team Exceldemy

  2. what is use to do a conditional alignment for a text?
    Seems like the #,##0_) ;(#,##0) only works for number alignment

    • Reply Lutfor Rahman Shimanto
      Lutfor Rahman Shimanto Jun 11, 2024 at 12:23 PM

      Hello there! Thanks for sharing an exciting problem. Since using the conditional formatting option for text alignment is impossible, you can only use an Excel VBA procedure.

      An Excel VBA event procedure was used to apply conditional alignment based on cell value

      Note: The event procedure will trigger when range B2:B7 is changed. If the cell value is Red, it will apply left alignment. For Blue, it will be center alignment; for the other values, it will apply left alignment. You can modify the code based on your needs.

      Excel VBA Event Procedure:

      Private Sub Worksheet_Change(ByVal Target As Range)
      
          Dim cell As Range
      
          Dim targetRange As Range
          Set targetRange = Me.Range("B2:B7")
      
          If Not Intersect(Target, targetRange) Is Nothing Then
              For Each cell In Intersect(Target, targetRange)
      
                  If cell.Value = "Red" Then
                      cell.HorizontalAlignment = xlLeft
                  ElseIf cell.Value = "Blue" Then
                      cell.HorizontalAlignment = xlCenter
                  Else
                      cell.HorizontalAlignment = xlRight
                  End If
              Next cell
          End If
      
      End Sub

      Hopefully, the solution will fulfil your goal. Download the attached solution workbook for a better understanding.

      DOWNLOAD SOLUTION WORKBOOK

      Regards
      Lutfor Rahman Shimanto
      Excel & VBA Developer
      ExcelDemy

    • Hello M-curious,

      To do a conditional formatting follow the steps of method 1. Instead of using custom option from format cells, you can use the Alignment options.
      Go to Format cells dialog box then from Alignment select any select any Alignments of your choice.

      Alignments

      Regards
      ExcelDemy

      • Look at the screenshots in the article/post and alignment, when applying conditional formatting, isn’t an option – if it were we wouldn’t be looking for workarounds…

        • Lutfor Rahman Shimanto
          Lutfor Rahman Shimanto Jun 11, 2024 at 12:05 PM

          Dear, Thanks for pointing out the fact! You are right. The Alignment tab in the Format Cells dialog box is unavailable when setting up conditional formatting rules. So, using the conditional formatting option for text alignment is impossible.

          Don’t worry! There is an idea of using an Excel VBA event procedure. Please check the following:

          An Excel VBA event procedure was used to apply conditional alignment based on cell value

          The event procedure will trigger when range B2:B7 is changed. If the cell value is Red, it will apply left alignment. For Blue, it will be center alignment; for the other values, it will apply left alignment.

          Excel VBA Event Procedure:

          Private Sub Worksheet_Change(ByVal Target As Range)
          
              Dim cell As Range
          
              Dim targetRange As Range
              Set targetRange = Me.Range("B2:B7")
          
              If Not Intersect(Target, targetRange) Is Nothing Then
                  For Each cell In Intersect(Target, targetRange)
          
                      If cell.Value = "Red" Then
                          cell.HorizontalAlignment = xlLeft
                      ElseIf cell.Value = "Blue" Then
                          cell.HorizontalAlignment = xlCenter
                      Else
                          cell.HorizontalAlignment = xlRight
                      End If
                  Next cell
              End If
          
          End Sub

          Hopefully, the solution will fulfil your goal. I have attached the solution workbook as well. Good luck.

          DOWNLOAD SOLUTION WORKBOOK

          Regards
          Lutfor Rahman Shimanto
          Excel & VBA Developer
          ExcelDemy

Leave a reply

Advanced Excel Exercises with Solutions PDF

 

 

ExcelDemy
Logo