+ Reply to Thread
Results 1 to 16 of 16

Column A & B Match then select cell from a variable adjacent column on same row

  1. #1
    Registered User
    Join Date
    01-31-2015
    Location
    London
    MS-Off Ver
    Excel 2019
    Posts
    91

    Column A & B Match then select cell from a variable adjacent column on same row

    My other attempts at solving what I need does not seem to be working so I am trying a different approach.


    I need a formula or a macro or VBA code that...

    Looks at all of Column A for the Number 1 and then looks at the whole of Column B for the Number 1.

    When it finds the row where these two numbers match then it places the value from the cell directly to it's right (Column C) from the matching row in to Cell G1 but I will need to be able to change it so that it may say that it should show the contents of the cell on the matching row from two columns to the right (Column D) or maybe three columns to the right (Column E) and so on.

    I have to do it this way because the match between column A and Column B can happen any where down the column so I specify which Cell in Column C to show in G1.

    I have attached (hopefully) an example spreadsheet.

    I don't know how else to explain this question...

    Thanks everyone.
    Attached Files Attached Files

  2. #2
    Forum Guru
    Join Date
    03-02-2006
    Location
    Los Angeles, Ca
    MS-Off Ver
    WinXP/MSO2007;Win10/MSO2016
    Posts
    12,621

    Re: Column A & B Match then select cell from a variable adjacent column on same row

    Start with:
    Please Login or Register  to view this content.
    Ben Van Johnson

  3. #3
    Forum Expert Tony Valko's Avatar
    Join Date
    12-31-2011
    Location
    Pittsburgh
    MS-Off Ver
    2002, 2007:2013
    Posts
    18,890

    Re: Column A & B Match then select cell from a variable adjacent column on same row

    This array formula** entered in G1:

    =INDEX(C1:C12,MATCH(1,(A1:A12=1)*(B1:B12=1),0))

    ** array formulas need to be entered using the key
    combination of CTRL,SHIFT,ENTER (not just ENTER).
    Hold down both the CTRL key and the SHIFT key
    then hit ENTER.

    To return data from other columns just change the red highlighted range to suit.
    Biff
    Microsoft MVP Excel
    Keep It Simple Stupid

    Let's Go Pens. We Want The Cup.

  4. #4
    Registered User
    Join Date
    01-31-2015
    Location
    London
    MS-Off Ver
    Excel 2019
    Posts
    91

    Re: Column A & B Match then select cell from a variable adjacent column on same row

    Quote Originally Posted by protonLeah View Post
    Start with:
    Please Login or Register  to view this content.
    Hi Thank you so much, this works great.

    I am going to use Tony Valko's suggestion as it also works but is easier for me to understand and modify.

    I really appreciate you taking the time to help.

    Thanks again

  5. #5
    Registered User
    Join Date
    01-31-2015
    Location
    London
    MS-Off Ver
    Excel 2019
    Posts
    91

    Re: Column A & B Match then select cell from a variable adjacent column on same row

    Quote Originally Posted by Tony Valko View Post
    This array formula** entered in G1:

    =INDEX(C1:C12,MATCH(1,(A1:A12=1)*(B1:B12=1),0))

    ** array formulas need to be entered using the key
    combination of CTRL,SHIFT,ENTER (not just ENTER).
    Hold down both the CTRL key and the SHIFT key
    then hit ENTER.

    To return data from other columns just change the red highlighted range to suit.
    Hi Tony

    Thanks for the post and for taking the time to help.

    Your code works excellently and does exactly what I need.

    Thanks again

  6. #6
    Registered User
    Join Date
    01-31-2015
    Location
    London
    MS-Off Ver
    Excel 2019
    Posts
    91

    Re: Column A & B Match then select cell from a variable adjacent column on same row

    Quote Originally Posted by Tony Valko View Post
    This array formula** entered in G1:

    =INDEX(C1:C12,MATCH(1,(A1:A12=1)*(B1:B12=1),0))

    ** array formulas need to be entered using the key
    combination of CTRL,SHIFT,ENTER (not just ENTER).
    Hold down both the CTRL key and the SHIFT key
    then hit ENTER.

    To return data from other columns just change the red highlighted range to suit.
    Hi Tony

    Thanks for the post and for taking the time to help.

    Your code works excellently and does exactly what I need.

    The only thing I notice is where Column A & B have a match but the is no text to return in
    the adjacent cells your code returns the number 0, is there a way so that it returns nothing?

    Thanks again

  7. #7
    Forum Expert Tony Valko's Avatar
    Join Date
    12-31-2011
    Location
    Pittsburgh
    MS-Off Ver
    2002, 2007:2013
    Posts
    18,890

    Re: Column A & B Match then select cell from a variable adjacent column on same row

    Like this...

    =IF(INDEX(C1:C12,MATCH(1,(A1:A12=1)*(B1:B12=1),0))="","",INDEX(C1:C12,MATCH(1,(A1:A12=1)*(B1:B12=1),0)))

    Still array entered.

  8. #8
    Registered User
    Join Date
    01-31-2015
    Location
    London
    MS-Off Ver
    Excel 2019
    Posts
    91

    Re: Column A & B Match then select cell from a variable adjacent column on same row

    Quote Originally Posted by Tony Valko View Post
    Like this...

    =IF(INDEX(C1:C12,MATCH(1,(A1:A12=1)*(B1:B12=1),0))="","",INDEX(C1:C12,MATCH(1,(A1:A12=1)*(B1:B12=1),0)))

    Still array entered.
    Hi Tony

    Wow thanks for the fast reply...

    One last question that Ive just encountered while learning how to use your array,

    How do I stipulate that Columns A & B are in a different worksheet....

    Say columns A & B are in a worksheet called 'Data_Input' but your array will be on a worksheet called 'Results' ?

    Would I use Data_Input!A1:Data_Input!A2 or even Data_Input!A1:A12 ?

  9. #9
    Forum Expert Tony Valko's Avatar
    Join Date
    12-31-2011
    Location
    Pittsburgh
    MS-Off Ver
    2002, 2007:2013
    Posts
    18,890

    Re: Column A & B Match then select cell from a variable adjacent column on same row

    Like this...

    =IF(INDEX(Data_Input!C1:C12,MATCH(1,(Data_Input!A1:A12=1)*(Data_Input!B1:B12=1),0))="","",INDEX(Data_Input!C1:C12,MATCH(1,(Data_Input!A1:A12=1)*(Data_Input!B1:B12=1),0)))

    Still array entered!

  10. #10
    Registered User
    Join Date
    01-31-2015
    Location
    London
    MS-Off Ver
    Excel 2019
    Posts
    91

    Re: Column A & B Match then select cell from a variable adjacent column on same row

    Dont worry about it, I just figured it out.

    I cant tell you how frustrated I have been over this and now, thanks to your array (and protonLeah's suggestion)
    it's solved.

    Thanks again

  11. #11
    Registered User
    Join Date
    01-31-2015
    Location
    London
    MS-Off Ver
    Excel 2019
    Posts
    91

    Re: Column A & B Match then select cell from a variable adjacent column on same row

    just noticed you replied, what a star, thank you again.

  12. #12
    Forum Expert Tony Valko's Avatar
    Join Date
    12-31-2011
    Location
    Pittsburgh
    MS-Off Ver
    2002, 2007:2013
    Posts
    18,890

    Re: Column A & B Match then select cell from a variable adjacent column on same row

    You're welcome. Thanks for the feedback!


    If your question has been solved please mark the thread as being solved.

    In the menu bar above the very first post select Thread Tools, then select Mark this thread as solved.

  13. #13
    Registered User
    Join Date
    01-31-2015
    Location
    London
    MS-Off Ver
    Excel 2019
    Posts
    91

    Re: Column A & B Match then select cell from a variable adjacent column on same row

    Hi Tony

    So sorry to have to come back to you yet again....


    The array is throwing up a different error now. When there is no data for the array to get (eg. A blank row) Its now showing #N/A.

    This is a bit of a pain as I have other formulas that look at your array and when the cell is empty (eg. there is no row for the array to return) they do something specific but of course as your array is returning #N/A the other formulas see that as a cell that has data.

    i know you have help me out plenty already but I would be very grateful this one last time.

    Thanks Tony...

  14. #14
    Forum Expert Tony Valko's Avatar
    Join Date
    12-31-2011
    Location
    Pittsburgh
    MS-Off Ver
    2002, 2007:2013
    Posts
    18,890

    Re: Column A & B Match then select cell from a variable adjacent column on same row

    Maybe this...

    =IFERROR(IF(INDEX(Data_Input!C1:C12,MATCH(1,(Data_Input!A1:A12=1)*(Data_Input!B1:B12=1),0))="","",INDEX(Data_Input!C1:C12,MATCH(1,(Data_Input!A1:A12=1)*(Data_Input!B1:B12=1),0))),"")

    Instead of an error that will return a blank.

    Still array entered.

  15. #15
    Registered User
    Join Date
    01-31-2015
    Location
    London
    MS-Off Ver
    Excel 2019
    Posts
    91

    Re: Column A & B Match then select cell from a variable adjacent column on same row

    Outstanding Tony - works like a dream.

    You really have saved me so much frustration, there is no way on earth that I would have been able to work out any of this on my own.

    It is my firm belief that excel formulas are a dark art only practiced by extremely knowledgeable excel wizards

    Thank you again Tony

  16. #16
    Forum Expert Tony Valko's Avatar
    Join Date
    12-31-2011
    Location
    Pittsburgh
    MS-Off Ver
    2002, 2007:2013
    Posts
    18,890

    Re: Column A & B Match then select cell from a variable adjacent column on same row

    You're quite welcome!

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Match Cell Substrings to Column and Return Adjacent Cell
    By ashb444 in forum Excel Formulas & Functions
    Replies: 9
    Last Post: 08-06-2015, 11:24 AM
  2. [SOLVED] VBA to add the contents of an adjacent variable column size
    By markDuffy in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 04-30-2015, 06:35 AM
  3. Need Formula to Match Text In a column And Retrieve adjacent column value
    By excel_joel in forum Excel Formulas & Functions
    Replies: 6
    Last Post: 03-06-2014, 02:08 AM
  4. [SOLVED] Set cell equal to variable cell (from set column) based on cells in adjacent column
    By alter54 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 01-24-2014, 01:04 PM
  5. Variable assignment in adjacent column
    By Spacelion in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 01-11-2013, 04:19 PM
  6. Find and Match Text in Column Return Adjacent Cell
    By biancam in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 07-11-2012, 02:45 PM
  7. Colour a cell if having a match in adjacent column
    By meetvivek72 in forum Excel General
    Replies: 3
    Last Post: 07-07-2011, 09:21 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1