+ Reply to Thread
Results 1 to 14 of 14

vlookup word in a column and count the # of rows between each use of the word

  1. #1
    Forum Contributor
    Join Date
    12-03-2008
    Location
    Key West, FL
    MS-Off Ver
    365 Apps for Enterprise
    Posts
    665

    Arrow vlookup word in a column and count the # of rows between each use of the word

    In the attached workbook I'm showing a small trading ledger which has one row per calendar day. I'm creating a new table which condenses this data into a format which has no empty rows, and which also takes some "column" data and transposes it into "row" data.

    Please note that I don't want to use a pivot table. I'd rather use formulas.

    I have had success creating a new table which eliminates the empty rows. But I need assistance with the next step, and that is to
    (a) locate each instance of the word "close" in Column C, then
    (b) give me data in the rows above it, up to but not including the preceding row which has "close" in Column C.

    As an example, when looking at the attached workbook the formula I need would give me row numbers 18,20, and 23. If I have those row numbers then I can create the formulas I need to insert the values in those rows into specific cells in the new table.

    I'm assuming this would involve vlookup, hlookup, and/or match. Or something similar?

    Any advice? Thanks so much!
    Attached Files Attached Files

  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. 2405 (Windows 11 23H2 64-bit)
    Posts
    81,417

    Re: vlookup word in a column and count the # of rows between each use of the word

    Please post your workbook again once you have manually added your expected outcomes.
    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
    Forum Expert
    Join Date
    07-20-2011
    Location
    Mysore, India.
    MS-Off Ver
    Excel 2019
    Posts
    8,615

    Re: vlookup word in a column and count the # of rows between each use of the word

    In sheet2 in A6,Array Formula, then drag across

    =IFERROR(INDEX(Sheet1!A$11:A$24,SMALL(IF(Sheet1!$C$11:$C$24="sell",ROW($C$11:$C$24),""),ROWS($A$6:$A6))-ROW($C$11)+1),"")

    Array formula should be confirmed with Ctrl+Shift+Enter keys together.
    Attached Files Attached Files

  4. #4
    Forum Contributor
    Join Date
    08-29-2017
    Location
    Canada
    MS-Off Ver
    Window 2013
    Posts
    127

    Re: vlookup word in a column and count the # of rows between each use of the word

    Could you also use a Sumifs for this one as well?

  5. #5
    Forum Expert
    Join Date
    07-20-2011
    Location
    Mysore, India.
    MS-Off Ver
    Excel 2019
    Posts
    8,615

    Re: vlookup word in a column and count the # of rows between each use of the word

    Update file showing what is expected result manually.

  6. #6
    Forum Contributor
    Join Date
    12-03-2008
    Location
    Key West, FL
    MS-Off Ver
    365 Apps for Enterprise
    Posts
    665

    Re: vlookup word in a column and count the # of rows between each use of the word

    Hi Ali, I've attached the workbook with the expected outcome. I also created a "check" to test the math on both worksheets.

    If you look at the Desired Outcome tab, you'll see the layout I'm going for, and also that I've used VLOOOKUP
    to get some of the numbers.


    The challenge here is to match the "close" date with the transactions above these "closes." I was thinking that I could
    somehow use a combination of row numbers, INDIRECT, HLOOKUP or other functions to fill this out.

    If it helps, the solution for this problem could also involve adding helper cells to the first tab. That would be fine.

    Please let me know if this makes sense.

    Thanks!!
    Attached Files Attached Files

  7. #7
    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. 2405 (Windows 11 23H2 64-bit)
    Posts
    81,417

    Re: vlookup word in a column and count the # of rows between each use of the word

    Will there always be a 7-day interval between the first buy or sell and the close price?

  8. #8
    Forum Contributor
    Join Date
    12-03-2008
    Location
    Key West, FL
    MS-Off Ver
    365 Apps for Enterprise
    Posts
    665

    Re: vlookup word in a column and count the # of rows between each use of the word

    No, the intervals will be random. Would it help if I reworked the sample ledger to show more transactions?

  9. #9
    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. 2405 (Windows 11 23H2 64-bit)
    Posts
    81,417

    Re: vlookup word in a column and count the # of rows between each use of the word

    It needs to be properly representative. Anyone trying to help will be looking for patterns in the data.

  10. #10
    Forum Contributor
    Join Date
    12-03-2008
    Location
    Key West, FL
    MS-Off Ver
    365 Apps for Enterprise
    Posts
    665

    Re: vlookup word in a column and count the # of rows between each use of the word

    OK, I'll add some more rows and transactions.

  11. #11
    Forum Contributor
    Join Date
    12-03-2008
    Location
    Key West, FL
    MS-Off Ver
    365 Apps for Enterprise
    Posts
    665

    Re: vlookup word in a column and count the # of rows between each use of the word

    OK, here's version 3. I've added some rows to show a more random pattern of transactions, and also clarified how P/L is calculated.

    Thanks.
    Attached Files Attached Files

  12. #12
    Forum Expert
    Join Date
    07-20-2011
    Location
    Mysore, India.
    MS-Off Ver
    Excel 2019
    Posts
    8,615

    Re: vlookup word in a column and count the # of rows between each use of the word

    ARRAY formulas , to be dragged down
    In J11

    =IFERROR(INDEX(Sheet1!$B$11:$B$25,SMALL(IF((Sheet1!$C$11:$C$25="close")*(ROW(Sheet1!$A$11:$A$25)>INDEX(ROW(Sheet1!$A$11:$A$25),MATCH('Expected Outcome'!$A11,Sheet1!$A$11:$A$25))),ROW(Sheet1!$A$11:$A$25),""),1)-ROW(Sheet1!$A$11)+1),"")

    In K11

    =IFERROR(INDEX(Sheet1!$I$11:$I$25,SMALL(IF((Sheet1!$C$11:$C$25="close")*(ROW(Sheet1!$A$11:$A$25)>INDEX(ROW(Sheet1!$A$11:$A$25),MATCH('Expected Outcome'!$A11,Sheet1!$A$11:$A$25))),ROW(Sheet1!$A$11:$A$25),""),1)-ROW(Sheet1!$A$11)+1),"")

    Array formula should be confirmed with Ctrl+Shift+Enter keys together.
    Attached Files Attached Files
    Pl note
    Array formula should be confirmed with Ctrl+Shift+Enter keys together.
    If answere is satisfactory press * to add reputation.

  13. #13
    Registered User
    Join Date
    07-08-2016
    Location
    USA
    MS-Off Ver
    Office 365, Office 2016 for PC & Mac, Office 2013, Office 2011 Mac
    Posts
    80

    Re: vlookup word in a column and count the # of rows between each use of the word

    Hi jrtaylor,


    Close Date Expected Outcome!J11:*
    Please Login or Register  to view this content.
    *if you do not have minifs this can be altered by using an Min-If array formula to get the same result as in the formula above.


    Close Price Expected Outcome!K11:
    Please Login or Register  to view this content.



    DMG
    Attached Files Attached Files

  14. #14
    Forum Contributor
    Join Date
    12-03-2008
    Location
    Key West, FL
    MS-Off Ver
    365 Apps for Enterprise
    Posts
    665

    Re: vlookup word in a column and count the # of rows between each use of the word

    Thanks so much everyone! Looks like both solutions work. I do have MINIFS so I'll use that formula.
    I really appreciate everyone's help

+ 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. Replies: 5
    Last Post: 08-17-2015, 10:55 AM
  2. [SOLVED] (Challenge) Sum Order From Count "Center" Word To Start Word & "Center" Word To End Word
    By sanju2323 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 03-31-2015, 12:58 AM
  3. macro if data in column a = set word to insert that column into sheet 2 or 3 based on word
    By ExcelBeginner326 in forum Excel Programming / VBA / Macros
    Replies: 11
    Last Post: 05-13-2014, 01:57 PM
  4. VBA to enter a word, find said word in string of column & copy to another column
    By tuneloon in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 06-29-2012, 11:59 AM
  5. Replies: 6
    Last Post: 02-24-2010, 07:07 AM
  6. How to open a Word.doc using VBA and count the words in the word.doc?
    By eijoah in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 11-05-2007, 12:58 AM
  7. [SOLVED] I want to count rows between the occurence of one word.
    By SM in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 11-07-2005, 04:40 PM

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