+ Reply to Thread
Results 1 to 15 of 15

Making part of a statement iterative in Excel

  1. #1
    Registered User
    Join Date
    04-20-2011
    Location
    Manchester, England
    MS-Off Ver
    Excel 2007
    Posts
    43

    Making part of a statement iterative in Excel

    I have a lookup that works for a single column:

    =IFERROR(INDEX($C$2:$C$145,MATCH(A2,$D$2:$D$145,0)),"")

    If A2 matches the range of values in D2 to D145, then output the corresponding C2 to C145 value in cell B2

    This populates column B2 successfully.

    How could I put that into a loop, so that the $D$2:$D$145 part iterates between column D and column GS? ($D$2:$D$145, $E$2:$E$145, $F$2:$F$145 etc)

    Really appreciate any hints from anyone at this point.
    Last edited by asparak; 01-23-2014 at 08:45 AM.

  2. #2
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: Making part of a statement iterative in Excel

    Hi,

    Are you asking if you can find the A2 value ANYWHERE in D2:GS145 and if so return the row number for use in the INDEX() function?
    Richard Buttrey

    RIP - d. 06/10/2022

    If any of the responses have helped then please consider rating them by clicking the small star icon below the post.

  3. #3
    Forum Guru Pete_UK's Avatar
    Join Date
    12-31-2011
    Location
    Warrington, England
    MS-Off Ver
    Office 2019 (still learning)
    Posts
    24,812

    Re: Making part of a statement iterative in Excel

    Do you mean that you want everything to be returned to cell B2?

    Or does A2 appear only once in that range D2:GS145 and you want to bring the corresponding data from column C?

    Pete

  4. #4
    Forum Expert XOR LX's Avatar
    Join Date
    04-18-2013
    Location
    Turin, Italy
    MS-Off Ver
    Office 365
    Posts
    7,742

    Re: Making part of a statement iterative in Excel

    Hi,

    Are you saying that if the lookup_value is not found in column D, then columns E and F should then be searched, in that order?

    Regards
    Click * below if this answer helped

    Advanced Excel Techniques: http://excelxor.com/

  5. #5
    Registered User
    Join Date
    04-20-2011
    Location
    Manchester, England
    MS-Off Ver
    Excel 2007
    Posts
    43

    Re: Making part of a statement iterative in Excel

    I'll use a single row as an explanation here:
    Column A has 21,209 items in it. I need to identify where each of those matches anywhere in this range of values, so that I can create a single 'results column' that can be cut and pasted back into a master spreadsheet.
    A2 in this example will only ever match once against a value in the range D2 to GS145. Once you have a match, no need to continue searching.
    C2 to C145 is the results I need to concatenate, based on the pattern match
    If A2 was found in L143, then C143 should be copied to B2
    If the cell in D2 to GS145 is blank, it can be ignored if that makes it easier.
    Last edited by asparak; 01-23-2014 at 06:19 AM. Reason: Missed a bit

  6. #6
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: Making part of a statement iterative in Excel

    Hi,

    I was sort of with you until you mentioned concatenation and pattern match and then you lost me completely.

    On the basis that a picture is worth a thousand words please upload an example workbook, (we don't need 21000 rows, a handful will do), clearly showing the data and results you expect. Manually enter the results and a note which clearly says in a narrative form how you've arrived at the results.

  7. #7
    Forum Expert XOR LX's Avatar
    Join Date
    04-18-2013
    Location
    Turin, Italy
    MS-Off Ver
    Office 365
    Posts
    7,742

    Re: Making part of a statement iterative in Excel

    "I was sort of with you until you mentioned concatenation and pattern match and then you lost me completely."

    Me too!

  8. #8
    Registered User
    Join Date
    04-20-2011
    Location
    Manchester, England
    MS-Off Ver
    Excel 2007
    Posts
    43

    Re: Making part of a statement iterative in Excel

    Book1.xls

    Sorry, I'm hoping it's actually a fairly simple solution. I just can't get it to do each column one after the other.

    Hope the attached explains

  9. #9
    Forum Expert XOR LX's Avatar
    Join Date
    04-18-2013
    Location
    Turin, Italy
    MS-Off Ver
    Office 365
    Posts
    7,742

    Re: Making part of a statement iterative in Excel

    Hi,

    One way. In B2 and copy down:

    =INDEX($C$2:$C$15,SUMPRODUCT(($D$2:$P$15=A2)*(ROW($D$2:$P$15)-MIN(ROW($D$2:$P$15))+1)))

    Regards

  10. #10
    Registered User
    Join Date
    04-20-2011
    Location
    Manchester, England
    MS-Off Ver
    Excel 2007
    Posts
    43

    Re: Making part of a statement iterative in Excel

    That's pretty close, but it is always returning a value to column B, even where there is not match. Would Wrapping in an IFERROR work?

  11. #11
    Forum Expert XOR LX's Avatar
    Join Date
    04-18-2013
    Location
    Turin, Italy
    MS-Off Ver
    Office 365
    Posts
    7,742

    Re: Making part of a statement iterative in Excel

    Ah, yes. Apologies.

    =IF(SUMPRODUCT(--($D$2:$P$15=A2))=0,"",INDEX($C$2:$C$15,SUMPRODUCT(($D$2:$P$15=A2)*(ROW($D$2:$P$15)-MIN(ROW($D$2:$P$15))+1))))

    Regards

  12. #12
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,605

    Re: Making part of a statement iterative in Excel

    I was initially impressed, then a little confused, by the first formula. It seemed to work but then, as I looked at it, came to the same conclusion as the OP.

    Still impressed, especially with the modified solution, as I'm sure I've seen similar questions in the past and had no idea how to approach them.

    I've taken the liberty of putting the formula into the sample workbook and adding some Conditional Formatting. This highlights the matches so serves as a cross check.

    Regards, TMS
    Attached Files Attached Files
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


  13. #13
    Registered User
    Join Date
    04-20-2011
    Location
    Manchester, England
    MS-Off Ver
    Excel 2007
    Posts
    43

    Re: Making part of a statement iterative in Excel

    Thanks to everyone. Still some dirty data to tidy up, but a lot less work to do now Might still make the deadline after all.

  14. #14
    Forum Expert XOR LX's Avatar
    Join Date
    04-18-2013
    Location
    Turin, Italy
    MS-Off Ver
    Office 365
    Posts
    7,742

    Re: Making part of a statement iterative in Excel

    @TMShucks

    Glad you liked the solution!

  15. #15
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,605

    Re: Making part of a statement iterative in Excel

    @Both: You're welcome.

    @asparak: Thanks for the rep.

+ 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. [SOLVED] Making the last part of this INDIRECT formula as relative
    By zicitron in forum Excel Formulas & Functions
    Replies: 9
    Last Post: 07-04-2020, 02:26 PM
  2. Help, Part 2: making the corrected data be just text?
    By clancy1104 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 10-06-2013, 11:19 AM
  3. making macro run auto when a third part result is met
    By myboss in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 11-15-2011, 04:01 AM
  4. Problem with Iterative Code, Excel Precision, or my maths??
    By Phil_V in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 05-19-2009, 09:59 AM
  5. Using Today() and making it Static based on a particular condition. Part-II
    By all4excel in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 06-04-2008, 03:49 AM

Tags for this Thread

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