ExcelDemy

How to Apply Alignment in Excel Conditional Formatting

Al Ikram Amit

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.

  • 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:
  • 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:

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* ;;;* @

  • 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:
  • 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:

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.
  • Choose Format.

Choose Format

  • The Format Cells pop-up will appear.

The Format Cells pop-up will appear

  • Plug in the following formula:
  • 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

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

What is ExcelDemy?

Tags: Excel Conditional Formatting

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

' src=

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

Abrar-ur-Rahman Niloy

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

' src=

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

Lutfor Rahman Shimanto

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

Avatar photo

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

' src=

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 .

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

Leave a reply Cancel reply

ExcelDemy is a place where you can learn Excel, and get solutions to your Excel & Excel VBA-related problems, Data Analysis with Excel, etc. We provide tips, how to guide, provide online training, and also provide Excel solutions to your business problems.

See Our Reviews at

trustpilot review

  • User Reviews
  • List of Services
  • Service Pricing
  • Create Basic Excel Pivot Tables
  • Excel Formulas and Functions
  • Excel Charts and SmartArt Graphics
  • Advanced Excel Training
  • Data Analysis Excel for Beginners

DMCA.com Protection Status

Advanced Excel Exercises with Solutions PDF

ExcelDemy

  • Ablebits blog
  • If Statement

How to use IF function in Excel: examples for text, numbers, dates, blanks

Svetlana Cheusheva

In this article, you will learn how to build an Excel IF statement for different types of values as well as how to create multiple IF statements.

IF is one of the most popular and useful functions in Excel. Generally, you use an IF statement to test a condition and to return one value if the condition is met, and another value if the condition is not met.

In this tutorial, we are going to learn the syntax and common usages of the Excel IF function, and then take a closer look at formula examples that will hopefully prove helpful to both beginners and experienced users.

IF function in Excel

IF is one of logical functions that evaluates a certain condition and returns one value if the condition is TRUE, and another value if the condition is FALSE.

The syntax of the IF function is as follows:

As you see, IF takes a total of 3 arguments, but only the first one is obligatory, the other two are optional.

Logical_test (required) - the condition to test. Can be evaluated as either TRUE or FALSE.

Value_if_true (optional) - the value to return when the logical test evaluates to TRUE, i.e. the condition is met. If omitted, the value_if_false argument must be defined.

Basic IF formula in Excel

To create a simple If then statement in Excel, this is what you need to do:

  • For logical_test , write an expression that returns either TRUE or FALSE. For this, you'd normally use one of the logical operators .
  • For value_if_true , specify what to return when the logical test evaluates to TRUE.
  • For value_if_false , specify what to return when the logical test evaluates to FALSE. Though this argument is optional, we recommend always configuring it to avoid unexpected results. For the detailed explanation, please see Excel IF: things to know .

As an example, let's write a very simple IF formula that checks a value in cell A2 and returns "Good" if the value is greater than 80, "Bad" otherwise:

=IF(B2>80, "Good", "Bad")

Basic IF formula in Excel.

In case you wish to return a value only when the condition is met (or not met), otherwise - nothing, then use an empty string ("") for the "undefined" argument. For example:

=IF(B2>80, "Good", "")

IF formula to return nothing when the condition is not met.

Excel If then formula: things to know

Though the last two parameters of the IF function are optional, your formula may produce unexpected results if you don't know the underlying logic.

If value_if_true is omitted

If the 2 nd argument of your Excel IF formula is omitted (i.e. there are two consecutive commas after the logical test), you'll get zero (0) when the condition is met, which makes no sense in most cases. Here is an example of such a formula:

=IF(B2>80, , "Bad")

To return a blank cell instead, supply an empty string ("") for the second parameter, like this:

=IF(B2>80, "", "Bad")

The behavior of the value_if_true argument.

If value_if_false is omitted

Omitting the 3 rd parameter of IF will produce the following results when the logical test evaluates to FALSE.

If there is just a closing bracket after value_if_true , the IF function will return the logical value FALSE. Quite unexpected, isn't it? Here is an example of such a formula:

=IF(B2>80, "Good")

Typing a comma after the value_if_true argument will force Excel to return 0, which doesn't make much sense either:

=IF(B2>80, "Good",)

The most reasonable approach is using a zero-length string ("") to get a blank cell when the condition is not met:

The behavior of the value_if_false argument.

Using IF function in Excel - formula examples

Now that you are familiar with the IF function's syntax, let's look at some formula examples and learn how to use If then statements in real-life scenarios.

Excel IF function with numbers

To build an IF statement for numbers, use logical operators such as:

  • Equal to (=)
  • Not equal to (<>)
  • Greater than (>)
  • Greater than or equal to (>=)
  • Less than (<)
  • Less than or equal to (<=)

Above, you have already seen an example of such a formula that checks if a number is greater than a given number.

And here's a formula that checks if a cell contains a negative number :

=IF(B2<0, "Invalid", "")

A formula to check if a cell contains a negative number.

Excel IF function with text

Commonly, you write an IF statement for text values using either "equal to" or "not equal to" operator.

For example, the following formula checks the Delivery Status in B2 to determine whether an action is required or not:

=IF(B2="delivered", "No", "Yes")

Using the IF function with text.

Another way to achieve the same result is to use the "not equal to" operator and swap the value_if_true and value_if_false values:

=IF(C2<>"delivered", "Yes", "No")

  • When using text values for IF's parameters, remember to always enclose them in double quotes .
  • Like most other Excel functions, IF is case-insensitive by default . In the above example, it does not differentiate between "delivered", "Delivered", and "DELIVERED".

Case-sensitive IF statement for text values

To treat uppercase and lowercase letters as different characters, use IF in combination with the case-sensitive EXACT function.

For example, to return "No" only when B2 contains "DELIVERED" (the uppercase), you'd use this formula:

Case-sensitive IF statement for text values.

If cell contains partial text

In situation when you want to base the condition on partial match rather than exact match, an immediate solution that comes to mind is using wildcards in the logical test. However, this simple and obvious approach won't work. Many functions accept wildcards, but regrettably IF is not one of them.

A working solution is to use IF in combination with ISNUMBER and SEARCH (case-insensitive) or FIND (case-sensitive).

For example, in case "No" action is required both for "Delivered" and "Out for delivery" items, the following formula will work a treat:

IF cell contains partial text.

For more information, please see:

  • Excel IF statement for partial text match
  • If cell contains then

Excel IF statement with dates

At first sight, it may seem that IF formulas for dates are akin to IF statements for numeric and text values. Regrettably, it is not so. Unlike many other functions, IF does recognize dates in logical tests and interprets them as mere text strings. In other words, you cannot supply a date in the form of "1/1/2020" or ">1/1/2020". To make the IF function recognize a date, you need to wrap it in the DATEVALUE function.

For example, here's how you can check if a given date is greater than another date:

=IF(B2>DATEVALUE("7/18/2022"), "Coming soon", "Completed")

Excel IF statement with dates.

Of course, there is nothing that would prevent you from entering the target date in a predefined cell (say E2) and referring to that cell. Just remember to lock the cell address with the $ sign to make it an absolute reference . For instance:

=IF(B2>$E$2, "Coming soon", "Completed")

To compare a date with the current date , use the TODAY() function. For example:

Excel IF statement for blanks and non-blanks

If you are looking to somehow mark your data based on a certain cell(s) being empty or not empty, you can either:

  • Use the IF function together with ISBLANK , or
  • Use the logical expressions ="" (equal to blank) or <>"" (not equal to blank).

The table below explains the difference between these two approaches with formula examples.

And now, let's see blank and non-blank IF statements in action. Suppose you have a date in column B only if a game has already been played. To label the completed games, use one of these formulas:

=IF(B2="", "", "Completed")

=IF(ISBLANK(B2), "", "Completed")

=IF($B2<>"", "Completed", "")

=IF(ISBLANK($B2)=FALSE, "Completed", "")

IF statement for blank and non-blank cells.

Check if two cells are the same

To create a formula that checks if two cells match, compare the cells by using the equals sign (=) in the logical test of IF. For example:

Check if two cells contain the same values.

To check if the two cells contain same text including the letter case, make your IF formula case-sensitive with the help of the EXACT function.

For instance, to compare the passwords in A2 and B2, and returns "Match" if the two strings are exactly the same, "Do not match" otherwise, the formula is:

Case-sensitive IF formula to check if two cells match.

IF then formula to run another formula

In all of the previous examples, an Excel IF statement returned values. But it can also perform a certain calculation or execute another formula when a specific condition is met or not met. For this, embed another function or arithmetic expression in the value_if_true and/or value_if_false arguments.

For example, if B2 is greater than 80, we'll have it multiplied by 7%, otherwise by 3%:

IF formula that runs another formula.

Multiple IF statements in Excel

In essence, there are two ways to write multiple IF statements in Excel:

  • Nesting several IF functions one into another
  • Using the AND or OR function in the logical test

Nested IF statement

Nested IF functions let you place multiple IF statements in the same cell, i.e. test multiple conditions within one formula and return different values depending on the results of those tests.

Assume your goal is to assign different bonuses based on the score:

  • Over 90 - 10%
  • 90 to 81 - 7%
  • 80 to 70 - 5%
  • Less than 70 - 3%

To accomplish the task, you write 3 separate IF functions and nest them one into another like this:

Nested IF statement.

For more formula examples, please see:

Excel IF statement with multiple conditions

To evaluate several conditions with the AND or OR logic, embed the corresponding function in the logical test:

For example, to return "Pass" if both scores in B2 and C2 are higher than 80, the formula is:

=IF(AND(B2>80, C2>80), "Pass", "Fail")

To get "Pass" if either score is higher than 80, the formula is:

Excel IF statement with multiple conditions.

For full details, please visit:

If error in Excel

Starting from Excel 2007, we have a special function, named IFERROR , to check formulas for errors. In Excel 2013 and higher, there is also the IFNA function to handle #N/A errors.

And still, there may be some circumstances when using the IF function together with ISERROR or ISNA is a better solution. Basically, IF ISERROR is the formula to use when you want to return something if error and something else if no error. The IFERROR function is unable to do that as it always returns the result of the main formula if it isn't an error.

For example, to compare each score in column B against the top 3 scores in E2:E4, and return "Yes" if a match is found, "No" otherwise, you enter this formula in C2, and then copy it down through C7:

If error formula in Excel.

Hopefully, our examples have helped you get a grasp of the Excel IF basics. I thank you for reading and hope to see you on our blog next week!

Practice workbook

You may also be interested in.

  • Excel IF function with multiple criteria
  • IF VLOOKUP in Excel
  • If cell contains then count, sum, highlight, copy or delete
  • Excel IF statement between two numbers or dates
  • Check if two cells match or multiple cells are equal

Table of contents

Ablebits.com website logo

4804 comments

conditional assignment in excel

Hi everybody, I am looking for help to check " If a date exist in Cell A then in Cell K to tell me what date will follow in -30 days.." Example Date of 10/Jun/2025 (cell A),-30 days (cell K) will result on 14/May/2025. I have the basic rule working but I would like the "IF" option. thank you in advance!

conditional assignment in excel

Hi Lorenzo! I hope you have studied the recommendations in the tutorial above. It contains answers to your question. If the cell is not blank, subtract 30.

=IF(ISBLANK(A1),"",A1-30)

conditional assignment in excel

Use If statement and compare against the database (Table 1) to to see if ID is Correct. Fill the red area with Correct or Incorrect result

Name ID Correct ? Table 1 Database Wayne 5 Name ID Bruce 3 Wayne 2 John 1

Hi! All the information you need to complete your learning task is available in the article above. I can't offer you the exact formula because your assignment doesn't specify what value you should compare to the database. If you understand your assignment, please explain it in more detail. If you need to compare two values then use this guide: IF AND in Excel: nested formula, multiple statements, and more .

conditional assignment in excel

Hello! How do I pull the a three digit number from a cell with text but if there are no numbers to just pull the text that is there in the cell?

Hello! You can extract a number from text in any of the ways described in this article and in the comments below this article: How to extract number from string in Excel . Then check the result using ISNUMBER function . If the number is not extracted, simply put in the text from the cell. For example:

=IF(ISNUMBER(--CONCAT(IF(ISNUMBER(--MID(A1,ROW($1:$50),1)),MID(A1,ROW($1:$50),1),""))), CONCAT(IF(ISNUMBER(--MID(A1,ROW($1:$50),1)),MID(A1,ROW($1:$50),1),"")), A1)

conditional assignment in excel

Hello! I have a budget spreadsheet with spending categories (Gas, rent, utilities) and I'd like to create a formula so that when I enter my new completed month (September for example), my sheet can automatically assign the Gas category for any line items that have "Shell" as the description. I would like that formula to do so for every recurring description I may have for grocery stores and gas stations I frequent the most. How would I write that out?

Hello Patrick! If I understand your task correctly, try the following formula:

=IF(ISNUMBER(SEARCH("Shell", A2)), "Gas", "")

For more information, please read: How to find substring in Excel . If the upper/lower case is important to you, use FIND function instead of SEARCH.

conditional assignment in excel

I need a formula that looks in column B and if the contents are matching, adds together the corresponding column E value. I'm not positive if an if/then formula will work since there are so many requirements. Thanks in advance for any help! Example: the answer would be A 3, D 3

A 2 D 3 A 1

Hi! Sorry, it's not quite clear what you are trying to achieve. If you want to find the sum based on some conditions, pay attention to SUMIFS function. For the detailed instructions, please see: Excel SUMIFS and SUMIF with multiple criteria – formula examples . If this does not help, explain the problem in detail.

conditional assignment in excel

How would I do a function that says "if cell 1 or greater than cell 2 by 10 more more ..." it's the "by 10 or more part i'm stumped on

Hi! Based on your description, it is hard to completely understand your task. However, I’ll try to guess and offer you the following guide: Excel IF OR statement with formula examples .

conditional assignment in excel

I need to sum by text from the number by multiple raw and.

Hi! Sorry, I do not fully understand the task. As it's currently written, it's hard to tell exactly what you're asking.

conditional assignment in excel

I think i need to write an if formaula with text. If a "number" is input into a cell i want it to return a "name". This is the formula i'm using but it's not returning the value needed...

IF(D5=1, DIGIOVANI, IF(D5=2, DURAN, IF(D5=3, GALLION-GOODMAN, IF(D5=4, PRO, IF(D5=5, RICHTER)))))

Hi! In formulas, always enclose text strings in double quotes: "DIGIOVANI"

Post a comment

IMAGES

  1. How to Create a Conditional Formula in Excel (5 Easy Ways)

    conditional assignment in excel

  2. Using Formulas for Conditional Formatting in Excel

    conditional assignment in excel

  3. Excel Conditional Formatting tutorial with examples

    conditional assignment in excel

  4. How to Create a Conditional Formula in Excel (5 Easy Ways)

    conditional assignment in excel

  5. Excel Conditional Formatting tutorial with examples

    conditional assignment in excel

  6. Excel 2016: Conditional Formatting

    conditional assignment in excel

VIDEO

  1. Excel Conditional formatting trick! #excelshorts

  2. EXCEL

  3. Advance Conditional formatting in excel (Sets Icon) #shortvideo #conditionalformatting #excel

  4. Restrictions on CELL in Excel #conditional_formatting#exceltips#excel#excelbasic#shortsviral#shorts

  5. Conditional Formatting in Excel Highlights Marks in Student #exceleducation #exceltricks

  6. Conditional formatting in in Excel #microsoftexcel