跳到主要內容

如何在Excel中將IF函數與AND,OR和NOT一起使用?

Excel 的 IF 函數證明了資料處理中邏輯運算的強大功能和多功能性。 IF 函數的本質是它評估條件並根據這些評估返回特定結果的能力。它的運作遵循一個基本邏輯:

=IF(condition, value_if_true, value_if_false)

當與 AND、OR 和 NOT 等邏輯運算子結合使用時,IF 函數的功能將顯著擴展。這種組合的強大之處在於它們能夠同時處理多種條件,提供能夠適應各種複雜場景的結果。在本教程中,我們將探討如何有效利用 Excel 中的這些強大功能來解鎖資料分析的新維度並增強您的決策過程。讓我們深入研究並發現這些強大的 Excel 函數的實際應用!

嵌套 IF AND OR NOT 公式


如果與公式

評估多種條件並提供特定結果 當滿足所有條件時 (TRUE),並且當任何條件不滿足 (FALSE) 時會產生不同的結果,您可以將 AND 函數合併到 IF 語句的邏輯測試中。其結構為:

=IF(AND(condition1, condition2, …), value_if_all_true, value_if_any_false)

例如,假設您是分析學生成績的老師。您想要根據兩個標準來決定學生是否通過: 分數高於70分 出席率超過80%.

  1. 首先檢查第一個學生的數據,他們的分數位於儲存格 B2 中,出席率位於儲存格 C2 中。對於該學生,在 D2 中應用以下公式:
    =IF(AND(B2>70, C2>80%), "Pass", "Fail")
    小提示: 此公式檢查 B2 的分數是否高於 70 分以及 C2 的出席率是否高於 80%。如果兩個條件都滿足,則傳回「Pass」;否則,返回“失敗”。
  2. 將公式向下拖曳到列中以評估每個學生的分數和出席率。

    如果與公式


如果或公式

評估多個條件並傳回特定結果 當滿足任一條件時 (TRUE),且當所有條件都不滿足時(FALSE)會得到不同的結果,因此可以在 IF 語句的邏輯測試中使用 OR 函數。公式結構如下:

=IF(OR(condition1, condition2, …), value_if_any_true, value_if_all_false)

例如,在教育背景下,考慮更靈活的學生通過標準。在這裡,如果學生滿足以下條件,則視為通過 得分高於 90 OR 出勤率高於95%.

  1. 首先評估第一個學生的表現,他們的分數在單元格 B2 中,出席率在單元格 C2 中。在相鄰單元格(例如 D2)中應用公式來評估:
    =IF(OR(B2>90, C2>95%), "Pass", "Fail")
    小提示: 此公式評估學生 B90 成績是否高於 2 分或 C95 出席率是否超過 2%。如果滿足任一條件,則傳回「Pass」;如果沒有,則“失敗”。
  2. 將此公式複製到列中,將其應用於清單中的每個學生,從而可以根據這些標準快速評估每個學生的通過資格。

    如果或公式


如果不是公式

評估條件並傳回特定結果 如果不符合條件(FALSE),並且如果滿足條件 (TRUE) 則得到不同的結果,IF 語句中的 NOT 函數就是您的解決方案。此公式的結構為:

=IF(NOT(condition), value_if_false, value_if_true)

舉一個實際的例子,考慮一個工作場所場景,其中員工獎金是根據他們的出勤記錄確定的。員工有資格獲得獎金,如果 未缺勤超過 3 天.

  1. 若要評估第一位員工的缺勤天數(其缺勤天數位於儲存格 B2 中),請使用下列公式:
    =IF(NOT(B2>3), "Eligible", "Not Eligible")
    小提示: 此公式檢查 B2 中缺勤的天數。如果不超過3,則傳回「Eligible」;否則,「不符合資格」。
  2. 將此公式複製到列中以將其應用於每個員工。

    如果不是公式


具有 IF 和邏輯函數的高階場景

在本節中,我們將探討 Excel 的 IF 函數與 AND、OR 和 NOT 等邏輯運算子的複雜用法。本節涵蓋從區分大小寫的計算到嵌套 IF 語句的所有內容,展示了 Excel 在複雜資料分析中的多功能性。


如果滿足你的條件,那麼計算

除了提供預先定義的結果外,Excel IF 函數與 AND、OR 和 NOT 等邏輯運算子結合使用時,還可以根據設定的條件是真還是假來執行各種計算。在這裡,我們將使用 IF AND 組合作為範例來展示此功能。

假設您正在管理一個銷售團隊並想要計算獎金。您決定一名員工 獲得銷售額 10% 的獎金 如果他們 銷售額超過 100 美元每週工作超過 30 小時.

  1. 對於初步評估,請查看 Alice 的數據,其中包括儲存格 B2 中的銷售額和儲存格 C2 中的工作時間。在 D2 中應用此公式:
    =IF(AND(B2>100, C2>30), B2*0.1, 0)
    小提示: 如果 Alice 的銷售額超過 10 美元且工作時間超過 100 小時,此公式會計算 Alice 銷售額的 30% 獎金。如果滿足兩個條件,則計算獎金;否則計算獎金。否則,返回 0。
  2. 透過將此公式複製到列中,將其擴展到團隊的其他成員。這種方法確保每個員工的獎金都是根據相同的標準計算的。

    IF 那麼計算

注意: 在本節中,我們將重點放在使用 IF 函數和 AND 來根據特定條件進行計算。此概念還可以擴展到包括 OR 和 NOT 以及巢狀邏輯函數,從而允許在 Excel 中進行各種條件計算。


區分大小寫的 AND、OR 和 NOT 語句

在 Excel 中,雖然 AND、OR 和 NOT 等邏輯函數通常不區分大小寫,但在某些情況下,文字資料中的區分大小寫至關重要。透過整合 精確函數 使用這些邏輯運算符,您可以有效地處理此類區分大小寫的情況。在本節中,我們以區分大小寫的方法為例來示範 IF 和 OR 函數的使用。

想像一個零售場景,如果產品符合以下任一條件,則該產品有資格進行促銷: 銷售額超過 100 美元 OR 在區分大小寫的檢查中,其代碼與“ABC”完全匹配.

  1. 對於第 2 行中列出的第一個產品,其銷售額位於儲存格 B2 中,產品代碼位於儲存格 C2 中,請在 D2 中使用下列公式:
    =IF(OR(B2>100, EXACT(C2,"ABC")), "Promotion Eligible", "Not Eligible")
    小提示: 此公式評估 B2 中的銷售額是否超過 100 美元或 C2 中的產品代碼恰好是「ABC」。滿足這些條件之一即可使該產品有資格進行促銷;兩者均不合格則不合格。
  2. 在所有產品的欄位中複製此公式,以根據銷售額和區分大小寫的產品代碼標準統一評估其促銷資格。

    區分大小寫的 IF OR 公式

注意: 在本節中,我們示範如何使用 IF 和 OR 函數以及 EXACT 函數來進行區分大小寫的計算。同樣,您可以在 IF 公式中應用 EXACT 函數,並結合 AND、OR、NOT 或巢狀邏輯函數,以滿足 Excel 中各種區分大小寫的要求。


將 IF 與嵌套的 AND、OR、NOT 語句集成

Excel 的 IF 函數與 AND、OR 和 NOT 嵌套時,提供了一個簡化的方法來處理更多層次的條件。本節提供了一個範例,展示這些巢狀函數在零售環境中的應用。

假設您正在監督一個負責各種產品類別的團隊,並且您想要確定他們的獎金資格。如果員工符合以下條件,則有資格獲得獎金: 銷售額超過 100 美元, 和任一 每週工作超過 30 小時 OR 不屬於電子部門。

  1. 首先,評估 Anne 的績效,她的銷售額在儲存格 B2 中,工作時間在儲存格 C2 中,部門在儲存格 D2 中。 E2 中的公式為:
    =IF(AND(B2>100, OR(C2>30, NOT(D2="Electronics"))), "Eligible", "Not Eligible")
    小提示: 此公式檢查 Anne 的銷售額是否超過 100 美元,且工作時間是否超過 30 小時或不從事電子產品工作。如果她符合這些標準,她就被視為「合格」;如果不符合,則「不符合資格」。
  2. 將此公式複製到每位員工的列中,以根據其銷售額、工作時間和部門來統一評估獎金資格。

    嵌套 IF AND OR NOT 公式


帶有 AND、OR、NOT 的巢狀 IF 函數

當資料分析涉及多個條件檢查時,Excel 中的嵌套 IF 函數提供了強大的解決方案。此方法需要為不同的條件建構單獨的 IF 語句,包括 AND、OR 和 NOT 邏輯,然後將它們整合到簡化的公式中。

考慮一個工作場所,其中 員工績效被評為“優秀”、“良好”或“一般” 基於 銷售、工作時間和政策遵守情況:

  • 「優秀」表示銷售額超過 150 美元且工作時間超過 35 小時。
  • 否則,銷售額超過 100 美元或違反政策不超過 1 次則為「良好」。
  • 如果這兩個條件都不滿足,則「公平」。

若要根據上述條件評估每位員工的績效,請執行以下操作:

  1. 從 Anne 的評估開始,其銷售額位於儲存格 B2 中,工作時間位於儲存格 C2 中,政策違規情況位於儲存格 D2 中。 E2中嵌套的IF公式為:
    =IF(AND(B2>150, C2>35), "Excellent", IF(OR(B2>100, NOT(D2>1)), "Good", "Fair"))
    小提示: 此公式首先檢查 Anne 的銷售和工時是否符合「優秀」標準。如果不是,則評估她是否符合「Good」資格。如果這兩個條件都不滿足,她就被歸類為「一般」。
  2. 將這個嵌套 IF 公式擴展到每位員工,以根據多個標準一致地評估他們的績效。

    巢狀 IF 函數


將 IF 與 AND OR NOT 結合使用:常見問題

本節旨在解決在 Microsoft Excel 中將 IF 與 AND、OR 和 NOT 結合使用的常見問題。

AND、OR 和 NOT 函數可以支援多少個條件?
  • AND 和 OR 函數最多可支援 255 個單獨的條件。但是,建議僅使用一些公式,以避免公式過於複雜而難以維護。
  • NOT 函數只接受一個條件。
我可以在這些函數中使用 、= 等運算子嗎?

當然,在Excel的AND、OR、NOT函數中,可以利用小於()、等於(=)、大於等於(>=)等運算子來建立條件。

為什麼這些函數中會出現#VALUE 錯誤?

如果公式不符合任何指定的條件或公式的結構有問題,Excel 的 AND、OR 和 NOT 函數中經常會出現 #VALUE 錯誤。它表示 Excel 無法正確解釋公式中的輸入或條件。


以上是與在 Excel 中使用 IF 與 AND、OR 和 NOT 函數相關的所有相關內容。我希望本教程對您有所幫助。如果您想探索更多 Excel 提示和技巧, 請點擊這裡 訪問我們廣泛收集的超過數千個教程。

Comments (72)
No ratings yet. Be the first to rate!
This comment was minimized by the moderator on the site
Hey Friends,

Donno if this Forum works now:

I am trying to figure out a formula for the following:
I have 3 Columns : viz : A1,D1, L1 with text contents. And output expected in M1

So if any of the cells A,D,L has Faulty mentioned, then M1 should result "Faulty", Else if all 3 are blank , need "Spare", and if any cell has any data then it shoud show "Mapped"
This comment was minimized by the moderator on the site
Kan iemand mij helpen met onderstaande voor het maken van een formule?
als B2 de tekst factuur staat moet in cel D8 de tekst factuurdatum komen te staan. Als in cel B2 de tekst offerte staat moet in cel D8 offertedatum komen te staan.

Alvast hartelijk dank
This comment was minimized by the moderator on the site
Hi there,

Can you show us the look of the text invoice, text quotation and text quotation date?
This comment was minimized by the moderator on the site
I am trying to write a formula to populate scores based off a range of values. This is what I have so far:

=IF(C2>=104.5%,"5", IF(C2<=104.49%,"4", IF(C2>=95.5%,"4", IF(C2<=95.49%,"3", IF(C2>=79.5%,"3", IF(C2<=79.49%,"2", IF(C2>=59.5%,"2", IF(C2<=59.49%,"1"""))))))))

The formula is working and I am not receiving any error messages. However, it is not populating the lower range values correctly. Here is my range:

>105% = 5
96%-105% = 4
80%-95% = 3
60%-79% = 2
<60% = 1

Any help is greatly appreciated.
This comment was minimized by the moderator on the site
Hi there,

I've fixed the formula as shown below:
=IF(C2>105%,"5",IF(C2>=96%,"4",IF(C2>=80%,"3",IF(C2>=60%,"2","1"))))

Hope this is what you want.

Amanda
This comment was minimized by the moderator on the site
Never mind, I figured it out. Thanks!
This comment was minimized by the moderator on the site
Kan iemand mij helpen aan onderstaande formule?
Alvast bedankt!

als Q groter is dan C dan Q en als Q kleiner is dan H dan H tenzij H 0 is dan is Q
This comment was minimized by the moderator on the site
Hi there,

Suppose, Q=A1, C=A2, H=A3. Please use the formula below: =IF(B1>B2,B1,IF(B1<B3,IF(B3=0,B1,B3),B3))

Hope this is what you want.

Amanda
This comment was minimized by the moderator on the site
I am trying to find a formula when realignment is in column A then add the text conflict when transition begins date (B) is >= the solution start date in column D OR if activation in column A then add the text conflict when transition begins date is <= solution start date in column D OR if deactivation then add the text conflict when transition begins date is >= the solution start date
A B C D E
Transition Type Transition Begins Transition Ends Solution Start Date Solution End Date
Realignment 11/1/2022 11/15/2022 1/15/2022 3/6/2022
Realignment 11/1/2022 11/15/2022 1/15/2022 3/16/2022
Realignment 11/1/2022 11/15/2022 6/1/2022 7/16/2022
Realignment 11/1/2022 11/15/2022 6/1/2022 7/16/2022
Realignment 11/1/2022 11/15/2022 6/1/2022 7/16/2022
Activation 1/1/2022 1/31/2022 1/15/2022 3/6/2022
Deactivation 12/1/2021 12/15/2021 1/15/2022 3/6/2022
Reorganization 2/6/2022 2/12/2022 1/15/2022 3/6/2022
Activation 12/1/2021 12/31/2021 11/1/2029 12/31/2029
Activation 12/1/2021 12/31/2021 2/1/2025 7/31/2025
Activation 12/1/2021 12/31/2021 4/1/2024 6/29/2024
Activation 12/1/2021 12/31/2021 2/1/2028 3/2/2028
Activation 12/1/2021 12/31/2021 2/1/2022 5/20/2025
Activation 12/1/2021 12/31/2021 9/6/2022 3/16/2023
Activation 12/1/2021 12/31/2021 6/1/2024 11/28/2024
Activation 12/1/2021 12/31/2021 9/1/2022 9/7/2022
Deactivation 10/1/2021 10/30/2021 11/1/2029 12/31/2029
Deactivation 10/1/2021 10/30/2021 2/1/2025 7/31/2025
Deactivation 10/1/2021 10/30/2021 4/1/2024 6/29/2024
Deactivation 10/1/2021 10/30/2021 2/1/2028 3/2/2028
Deactivation 10/1/2021 10/30/2021 2/1/2022 5/20/2025
Deactivation 10/1/2021 10/30/2021 9/6/2022 3/16/2023
Deactivation 10/1/2021 10/30/2021 6/1/2024 11/28/2024
Deactivation 10/1/2021 10/30/2021 9/1/2022 9/7/2022
Reorganization 2/1/2022 2/28/2022 11/1/2029 12/31/2029
Reorganization 2/1/2022 2/28/2022 2/1/2025 7/31/2025
This comment was minimized by the moderator on the site
Hi there,

What do you mean by adding the text conflict? Can you show me the result you want?

Amanda
This comment was minimized by the moderator on the site
=IF(AND(AY7>60,AY7>30),"0.02","0.04"),if(and(ay7<=30,ay<az),"0.06"),if(and(ay7<=15,ay<az),"0.08")
This comment was minimized by the moderator on the site
I am trying use If formula for one oridinary file, lets say I have number from 1 to 31 in a perticular cell. I need to show the result in another cell as if number in that perticular cell is less than 26 they it will zero, if the number in that perticular cell is from 26 to 30 then it will show the same number but if the number is abobe 30 then it will show the 30 only....Can anyone advise me how can I formulate this formula?
This comment was minimized by the moderator on the site
Hi there,

Please try the formula below: =IF(A1<26,0,IF(A1<=30,A1,30))

Hope this could help you.

Amanda
This comment was minimized by the moderator on the site
Ciao,
mi potete aiutare perfavore...
ho tre celle:
1-data di pagamento
2-totale
3-totale se pagato

vorrei che quando inserisco la data di pagamento(1), la casella 3(che è vuota) si riempisse automaticamente come la casella 2
come posso fare?
This comment was minimized by the moderator on the site
Hi there,

Do you want to fill the value of the cell 2 in the cell 3?
If so, you can enter this IF formula in the casella 3: =IF(casella 1<>"",casella 2,"")

Amanda
This comment was minimized by the moderator on the site
=IF(D4<=30000, and =>20000,than D4a-5000,and if(d4<=40000, and >30000, than d4-6000) convert into formula
This comment was minimized by the moderator on the site
Try the formula. Since I don't quite understand you, please check and change the part "DA4-5000" and "D4-6000", "FALSE" to the results you want.
=IF(AND(D4<=30000,D4>20000),"DA4-5000",IF(AND(D4<=40000,D4>30000),"D4-6000","FALSE"))
Amanda
This comment was minimized by the moderator on the site
HI EVERY ONE I NEED HELP IN THIS SYNTEX=IF(AND(AJ=1250,AJ*2.5%),IF(AND(AJ>1250,AJ<=2500),AJ*10%,IF(AND(AJ>2500,AJ<=3750),AJ*15%,IF(AND(AJ>3750,AJ<=11666),AJ*20%))))
THIS FOURMAIL GIVE ME #NAME WHERE THE EROO
This comment was minimized by the moderator on the site
Hi ahmed.dba,
Can you send the file to ? And if you have private information in the file, please delete them.
Amanda
There are no comments posted here yet
Load More
Please leave your comments in English
Posting as Guest
×
Rate this post:
0   Characters
Suggested Locations