To demonstrate alignment using conditional formatting, we have a sample data table like the image below.
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.
#,##0* ;;;* @
Steps:
- Select the Color column, then go to Home and select Conditional Formatting, then select New Rule.
- The New Formatting Rule pop-up will appear like the image below.
- 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.
- The Format Cells pop-up will appear.
- Go to Custom under the Number tab.
- Enter the following formula:
#,##0* ;;;* @
- Click OK.
- In New Formatting Rule, hit the OK.
- Blue has changed its alignment from left to right using conditional formatting.
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.
- 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.
- The Format Cells window will appear.
- 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.
- Select OK to complete the procedure.
- The cells containing values more than 15 have aligned in the middle.
- 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.
- 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.
- Press the OK button in New Formatting Rule.
- Numbers bigger than 15 have been shifted from right to left utilizing 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
- How to Make Yes Green and No Red in Excel
- How to Create a Rating Scale in Excel
- How to Use Conditional Formatting on Text Box in Excel
- How to Apply Borders in Excel with Conditional Formatting
- How to Copy Conditional Formatting to Another Cell in Excel
- How to Copy Conditional Formatting Color to Another Cell in Excel
- How to Copy Conditional Formatting to Another Sheet
- How to Copy Conditional Formatting But Change Reference Cell in Excel
<< Go Back to Conditional Formatting | Learn Excel
Get FREE Advanced Excel Exercises with Solutions!
Curious how this is accomplished if you want your number values to have 2 or more decimal places
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
what is use to do a conditional alignment for a text?
Seems like the #,##0_) ;(#,##0) only works for number alignment
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.
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:
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.
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…
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:
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:
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