+ Reply to Thread
Results 1 to 7 of 7

Find string, then find immediately below matched string find the word "subtotal" then ...

  1. #1
    Registered User
    Join Date
    06-22-2022
    Location
    AU
    MS-Off Ver
    Microsoft 365 Enterprise, v2204 b15128.20280
    Posts
    3

    Find string, then find immediately below matched string find the word "subtotal" then ...

    Hey knowledge well. I've been experimenting with vlookup/hlookups and not really getting far. Just looking for some advice please.

    If I have a bunch of order numbers in one sheet, called "orders" and there's no heading, it's simply at A1 an order number exists, of say "P1988", and then another one at A2 "P2042" so on and so forth ...

    How do I use that list of order numbers to then go and search across another sheet (in the same spreadsheet) called, "timesheets" to do the following.

    Using cell A1 in "orders" lookup that number in column B of "timesheets" (ignoring the first 10 rows) from row 11 down, and when that order number is found, search down in the same column B until you find the word "subtotal", when "Subtotal" is found, move right 11 columns and when you land on that value in column M, copy the value in that cell back to the "orders" sheet in cell B1

    so on and so forth, until the end of the list is reached in orders with a corresponding value.

    Thanks all, appreciate any pointers.

  2. #2
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2404 (Windows 11 22H2 64-bit)
    Posts
    80,955

    Re: Find string, then find immediately below matched string find the word "subtotal" then

    Welcome to the forum.

    There are instructions at the top of the page explaining how to attach your sample workbook.

    A good sample workbook has just 10-20 rows of representative data that has been desensitised. It also has expected results mocked up, relevant cells highlighted and a few explanatory notes.
    Ali


    Enthusiastic self-taught user of MS Excel who's always learning!
    Don't forget to say "thank you" in your thread to anyone who has offered you help.
    You can reward them by clicking on * Add Reputation below their user name on the left, if you wish.

    Forum Rules (updated August 2023): please read them here.

  3. #3
    Valued Forum Contributor
    Join Date
    07-23-2013
    Location
    London, England
    MS-Off Ver
    Office 365
    Posts
    988

    Re: Find string, then find immediately below matched string find the word "subtotal" then

    This would be a lot easier with a sample workbook. But, something like this?

    =INDEX(Timesheets!$M$11:$M$100,MATCH("Subtotal",INDEX(Timesheets!$B$11:$B$100,MATCH(A1,Timesheets!$B$11:$B$100,0)):Timesheets!$B$100,0)+MATCH(A1,Timesheets!$B$11:$B$100,0)-1)

  4. #4
    Registered User
    Join Date
    06-22-2022
    Location
    AU
    MS-Off Ver
    Microsoft 365 Enterprise, v2204 b15128.20280
    Posts
    3

    Re: Find string, then find immediately below matched string find the word "subtotal" then

    Thanks Ali for the reminder, and to Nick for a proposed solution (and so quickly after the posting).

    I've uploaded a sample file called "ExampleOrder2.xlsx" with two sheets, I have provided some comments in those sheets too.

    Thanks again
    Attached Files Attached Files

  5. #5
    Valued Forum Contributor
    Join Date
    07-23-2013
    Location
    London, England
    MS-Off Ver
    Office 365
    Posts
    988

    Re: Find string, then find immediately below matched string find the word "subtotal" then

    Ok, a slight tweak, but try:

    =INDEX(timesheet!$L$12:$L$1000,MATCH("Subtotal",INDEX(timesheet!$B$12:$B$1000,MATCH("*"&A2&"*",timesheet!$B$12:$B$1000,0)):timesheet!$B$1000,0)+MATCH("*"&A2&"*",timesheet!$B$12:$B$1000,0)-1)

  6. #6
    Registered User
    Join Date
    06-22-2022
    Location
    AU
    MS-Off Ver
    Microsoft 365 Enterprise, v2204 b15128.20280
    Posts
    3

    Re: Find string, then find immediately below matched string find the word "subtotal" then

    Oh jeeze, that works thanks so much ...
    I'd love to try and break this down a bit. I've probably missed parts, happy to be corrected so I can understand this better.
    INDEX (i.e., create an index over the timesheet across the L column down from rows 12 to 1000 MATCH it against
    "Subtotal", but create another index of "subtotal" across column B down 1000 rows, MATCH it against
    A2 relative, against timesheet column B up to 1000 rows,
    but then get a bit lost :P
    Cheers though, really appreciate it.

  7. #7
    Valued Forum Contributor
    Join Date
    07-23-2013
    Location
    London, England
    MS-Off Ver
    Office 365
    Posts
    988

    Re: Find string, then find immediately below matched string find the word "subtotal" then

    I'll try and explain, hopefully it helps.

    Working from the middle out...

    MATCH("*"&A2&"*",timesheet!$B$12:$B$1000,0)
    Finds the first row where column B contains your job number (e.g. "P1988"). In this case it will return 1 as it's the first row of the range.

    INDEX(timesheet!$B$12:$B$1000,MATCH("*"&A2&"*",timesheet!$B$12:$B$1000,0))
    Uses this result to define the start of the range to look for "Subtotal". Note you can use index to define the start or end of a range, e.g. INDEX(A:A,1):A5 will resolve as A1:A5

    MATCH("Subtotal",INDEX(timesheet!$B$12:$B$1000,MATCH("*"&A2&"*",timesheet!$B$12:$B$1000,0)):timesheet!$B$1000,0)
    Finds the first row where column B equals "Subtotal", after finding P1988 as per steps above. It will start counting from the previous result. In this case there's no difference as the first result was 1, but this will return 38.

    INDEX(timesheet!$L$12:$L$1000,MATCH("Subtotal",INDEX(timesheet!$B$12:$B$1000,MATCH("*"&A2&"*",timesheet!$B$12:$B$1000,0)):timesheet!$B$1000,0)+MATCH("*"&A2&"*",timesheet!$B$12:$B$1000,0)-1)
    Adds the two MATCH results together and subtracts 1 to get the right row reference (38+1-1), then uses that within another INDEX to return the value from column L of this row.

+ 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] userform command button to "find" specific string?
    By PrimePorkchop in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 12-19-2021, 06:11 AM
  2. Using "IFS" and FIND for text with partly similar string
    By Rianne in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 02-05-2018, 06:04 AM
  3. Replies: 6
    Last Post: 11-27-2016, 09:53 AM
  4. [SOLVED] Does not cosistantly find a text string using "InStr" function
    By Bobbbo in forum Excel Programming / VBA / Macros
    Replies: 14
    Last Post: 03-21-2016, 08:37 PM
  5. [SOLVED] Convert string "MMM-yy" to date in VBA and then find the previous month
    By behumble in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 10-09-2013, 12:32 AM
  6. [SOLVED] Search numbers in a text string, find largest "value" return a value
    By OilGasKing in forum Excel Formulas & Functions
    Replies: 7
    Last Post: 02-27-2013, 09:01 PM
  7. The string of "Find what:" in Find and Replace dialog box to always highlight itself
    By chrisneu in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 11-23-2009, 09:04 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