• Skip to main content
  • Skip to header right navigation
  • Skip to site footer

My Online Training Hub

Learn Dashboards, Excel, Power BI, Power Query, Power Pivot

  • Courses
  • Pricing
    • SALE 20% Off All Courses
    • Free Courses
    • Power BI Course
    • Excel Power Query Course
    • Power Pivot and DAX Course
    • Excel Dashboard Course
    • Excel PivotTable Course – Quick Start
    • Advanced Excel Formulas Course
    • Excel Expert Advanced Excel Training
    • Excel Tables Course
    • Excel, Word, Outlook
    • Financial Modelling Course
    • Excel PivotTable Course
    • Excel for Customer Service Professionals
    • Multi-User Pricing
  • Resources
    • Free Downloads
    • Excel Functions Explained
    • Excel Formulas
    • Excel Add-ins
    • IF Function
      • Excel IF Statement Explained
      • Excel IF AND OR Functions
      • IF Formula Builder
    • Time & Dates in Excel
      • Excel Date & Time
      • Calculating Time in Excel
      • Excel Time Calculation Tricks
      • Excel Date and Time Formatting
    • Excel Keyboard Shortcuts
    • Excel Custom Number Format Guide
    • Pivot Tables Guide
    • VLOOKUP Guide
    • ALT Codes
    • Excel VBA & Macros
    • Excel User Forms
    • VBA String Functions
  • Members
    • Login
    • Logout
    • Password Reset
  • Blog
  • Excel Webinars
  • Excel Forum
    • Register as Forum Member

Formula If AND|General Excel Questions & Answers|Excel Forum|My Online Training Hub

You are here: Home / Formula If AND|General Excel Questions & Answers|Excel Forum|My Online Training Hub

sale now on

Avatar
sp_LogInOut Log In sp_Registration Register
sp_Search Search
Advanced Search
Search
Forum Scope




Match



Forum Options



Minimum search word length is 3 characters - maximum search word length is 84 characters
sp_Search Search
sp_RankInfo
Lost password?
sp_CrumbsHome HomeExcel ForumGeneral Excel Questions & Answe…Formula If AND
sp_PrintTopic sp_TopicIcon
Formula If AND
Avatar
Estella Foo

Active Member
Members
Level 0
Forum Posts: 4
Member Since:
August 24, 2016
sp_UserOfflineSmall Offline
1
September 12, 2017 - 10:58 pm
sp_Permalink sp_Print

Hi Mynda,

I tried to write a formula using If AND for my worksheet, but it seems only working for first row, and error if I scroll down or right.Confused

'IF(AND(Sheet2!A2=Sheet1!$A2,Sheet2!B2=Sheet1!B$1),Sheet2!C2&" "&Sheet2!D2,"NIL")

Would you please let me know my mistakes. 

 

Thank you.

sp_AnswersTopicSeeAnswer See Answer
Avatar
Anders Sehlstedt
Eskilstuna, Sweden

VIP
Members


Trusted Members
Level 3
Forum Posts: 858
Member Since:
December 7, 2016
sp_UserOfflineSmall Offline
2
September 13, 2017 - 5:06 am
sp_Permalink sp_Print

Hello Estella,

I changed your formula in cell Sheet1!B2 a bit, locked either the column or row reference and then copied it over the remaining cells.

=IF(AND(Sheet2!$A2=Sheet1!$A2;Sheet2!$B2=Sheet1!B$1);Sheet2!$C2&" "&Sheet2!$D2;"NIL")

As you have set the workbook to manual calculation you need to press F9 after you have copied the formula to the remaining cells.
See attached file for reference.

Br,
Anders

Avatar
Estella Foo

Active Member
Members
Level 0
Forum Posts: 4
Member Since:
August 24, 2016
sp_UserOfflineSmall Offline
3
September 13, 2017 - 10:18 pm
sp_Permalink sp_Print

Hi Anders,

Thank you for your help.

In fact I am looking at the result "customer" & "Free Goods" appear at each of the sales month as long as it meet or fall under the criteria "model" & " sales month".  So I rewrite it as below.   

IF(AND(Sheet2!$A2:$A13=Sheet1!$A2,Sheet2!$B2:$B13=Sheet1!B$1),Sheet2!$C2&" "&Sheet2!$D2,"NIL")

I am not sure whether this is the right formula to use if I want to see this result.  would you please advise.

 

Thank you.

 

EstellaSmile

Avatar
Anders Sehlstedt
Eskilstuna, Sweden

VIP
Members


Trusted Members
Level 3
Forum Posts: 858
Member Since:
December 7, 2016
sp_UserOfflineSmall Offline
4
September 14, 2017 - 5:14 am
sp_Permalink sp_Print sp_EditHistory

Hello Estella,

First things first, the way the current formula is built we need to have the same amount of rows as the lookup range has, so by extending the number of rows and copy the formula to the new blank cells you will get a result.

In order to get what you want we need to dig a bit deeper in how to build the formula, we need to use INDEX and MATCH plus finish the formula by holding down both SHIFT and CTRL keys before we press the ENTER key, we need to build an array formula.

The formula would be like below.
{=IFNA(INDEX(Sheet2!$A$2:$D$13,MATCH(1,(Sheet2!$A$2:$A$13=Sheet1!$A19)*(Sheet2!$B$2:$B$13=Sheet1!B$18),0),3)&" "&INDEX(Sheet2!$A$2:$D$13,MATCH(1,(Sheet2!$A$2:$A$13=Sheet1!$A19)*(Sheet2!$B$2:$B$13=Sheet1!B$18),0),4),"NIL")}

See attached file for an example for both scenarios.

Now I assume you want to understand more of how the array formula works. For that I believe there is a suitable course here at My Online Training Hub, but I will do an attempt to explain it.

As you see there are two INDEX functions, this is because you want to have a combined result from two different columns but the INDEX function can only give you the result from the intersection of a range, it can only give us one value.

So the first INDEX function get the result from column 3 (Customer)

INDEX(Sheet2!$A$2:$D$13,MATCH(1,(Sheet2!$A$2:$A$13=Sheet1!$A19)*(Sheet2!$B$2:$B$13=Sheet1!B$18),0),3)

and the second from column 4 (Free Goods)

INDEX(Sheet2!$A$2:$D$13,MATCH(1,(Sheet2!$A$2:$A$13=Sheet1!$A19)*(Sheet2!$B$2:$B$13=Sheet1!B$18),0),4)

To break this down a bit further.

The INDEX function has two methods, the array form or reference form. Here I use the array form and it looks like INDEX(array, row_num, [column_num]).
As you see in below sample I have colour coded the sections, so you can see what is what.

INDEX(Sheet2!$A$2:$D$13,MATCH(1,(Sheet2!$A$2:$A$13=Sheet1!$A19)*(Sheet2!$B$2:$B$13=Sheet1!B$18),0),3)

As there are two criterias to find the correct row, we need to use MATCH function. More about how to use INDEX and MATCH functions is found here.
MATCH syntax is MATCH(lookup_value, lookup_array, [match_type]).

MATCH(1,(Sheet2!$A$2:$A$13=Sheet1!$A19)*(Sheet2!$B$2:$B$13=Sheet1!B$18),0)

We instruct here MATCH to look for the value of 1, just because the result of the criterias lookup will result in a TRUE or FALSE value, that is 1 or 0. As we are looking for a row where the two different criterias are true, MATCH will give the value of 1 where the lookup in the range is true.

As we will get a #N/A value where we don't get any value, we need to enclose this with the IFNA() function, here we can type in that instead of #N/A value we want to have NIL.

As we have used arrays to look for the values instead of specific lookup value we need to finish this formula by holding down CTRL+SHIFT and then press ENTER. Otherwise we will get a #VALUE! error.

I hope I have not messed things up, but if so I trust that Mynda or anyone else in this excellent team will correct me. Smile

Br,
Anders

sp_AnswersTopicAnswer
Answers Post
Avatar
Estella Foo

Active Member
Members
Level 0
Forum Posts: 4
Member Since:
August 24, 2016
sp_UserOfflineSmall Offline
5
September 14, 2017 - 10:44 pm
sp_Permalink sp_Print

hi Anders,

Thank you for your help. It is great to know more formulas in excel to ease my work.

I will definitely look up more courses in how to use these 2 and also array formula.

 

Thank you.

Estella

sp_Feed
Go to top
Forum Timezone: Australia/Brisbane
Most Users Ever Online: 170
Currently Online: Jose Molina, Dieneba NDIAYE
Guest(s) 114
Currently Browsing this Page:
1 Guest(s)
Top Posters:
SunnyKow: 1432
Anders Sehlstedt: 858
Velouria: 580
Purfleet: 412
Frans Visser: 346
David_Ng: 306
lea cohen: 214
A.Maurizio: 202
Aye Mu: 201
Jessica Stewart: 189
Newest Members:
Richard Adams
Vincent Starcevich
Patrick Lawrence
Louise Bell
GIJO GEORGE
Kumud Patel
Atos Franzon
Andrew MacDonald
Artie Ball
Jenn Cain
Forum Stats:
Groups: 3
Forums: 24
Topics: 6079
Posts: 26684

 

Member Stats:
Guest Posters: 49
Members: 31571
Moderators: 2
Admins: 4
Administrators: Mynda Treacy, Philip Treacy, Catalin Bombea, FT
Moderators: MOTH Support, Riny van Eekelen
© Simple:Press —sp_Information

Sidebar

Blog Categories

  • Excel
  • Excel Charts
  • Excel Dashboard
  • Excel Formulas
  • Excel PivotTables
  • Excel Shortcuts
  • Excel VBA
  • General Tips
  • Online Training
  • Outlook
  • Power Apps
  • Power Automate
  • Power BI
  • Power Pivot
  • Power Query
trustpilot excellent rating
 

Company

  • About My Online Training Hub
  • Disclosure Statement
  • Frequently Asked Questions
  • Guarantee
  • Privacy Policy
  • Terms & Conditions
  • Testimonials
  • Become an Affiliate

Support

  • Contact
  • Forum
  • Helpdesk - For Technical Issues

Copyright © 2023 · My Online Training Hub · All Rights Reserved

Microsoft and the Microsoft Office logo are trademarks or registered trademarks of Microsoft Corporation in the United States and/or other countries. Product names, logos, brands, and other trademarks featured or referred to within this website are the property of their respective trademark holders.