+ Reply to Thread
Results 1 to 34 of 34

Find range of text, parse and copy (for..each?) rows until next range found

  1. #1
    Registered User
    Join Date
    05-02-2020
    Location
    Vancouver, Canada
    MS-Off Ver
    Office 2019
    Posts
    68

    Question Find range of text, parse and copy (for..each?) rows until next range found

    I've got an export from a program that will be pasted into an empty sheet. It'll look roughly like this:
    Please Login or Register  to view this content.
    Looking to have VBA run through that column; search for cells starting with L, parse the number range (ie 40-43), copying all to a new sheet.
    The new sheet will end up starting with L1, next row (then bunch of rows of copied text) then on another row L2 (bunch of rows), L3 (rows), L4 (rows), etc. etc.

    So the rows L40-43 above will end up looking as:
    Please Login or Register  to view this content.
    Added an example .xls; sheet 1 shows what is imported, sheet 2 results needed.

    Sorry for the excessive rows in this post to explain.
    Attached Files Attached Files
    Last edited by purgamentum; 05-07-2020 at 02:30 AM.

  2. #2
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,525

    Re: Find range of text, parse and copy (for..each?) rows until next range found

    Here's how I read your problem and the result is slightly different from yours, so you need to verify.
    Out put the result in Col.C
    Please Login or Register  to view this content.

  3. #3
    Registered User
    Join Date
    05-02-2020
    Location
    Vancouver, Canada
    MS-Off Ver
    Office 2019
    Posts
    68

    Re: Find range of text, parse and copy (for..each?) rows until next range found

    Quote Originally Posted by jindon View Post
    Here's how I read your problem and the result is slightly different from yours, so you need to verify.
    That's absolutely fantastic! Exactly what I was hoping to achieve.
    Thank you so very much jindon .. looking at that code, I'd be here 'till 2022!

  4. #4
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,525

    Re: Find range of text, parse and copy (for..each?) rows until next range found

    You are welcome and thanks for the rep.

    If that takes care of your original question, please select Thread Tools from the menu link above and mark this thread as SOLVED.

  5. #5
    Registered User
    Join Date
    05-02-2020
    Location
    Vancouver, Canada
    MS-Off Ver
    Office 2019
    Posts
    68

    Re: Find range of text, parse and copy (for..each?) rows until next range found

    Odd. I deleted the column and ran again, with different result - unless I wasn't seeing it the 1st time around. A1 starts with L17, the results now start with L0 and continue and L17 (I pasted to the right for a smaller /snip) are those of L18:
    Attachment 676479
    First run through I was sure it was exact.

    edit: I can have the other program change the "L" (which I probably should); would this be easy to change to "Level" instead?
    Last edited by purgamentum; 05-07-2020 at 12:39 AM.

  6. #6
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,525

    Re: Find range of text, parse and copy (for..each?) rows until next range found

    Your attachment is invalid, so can not open.

    If you upload a workbook, it will help.

    Please attach a sample workbook (not a picture or pasted copy). Make sure there is just enough data to demonstrate your need. Include a BEFORE sheet and an AFTER sheet in the workbook if needed to show the process you're trying to complete or automate. Make sure your desired results are shown, mock them up manually if necessary.

    Remember to desensitize the data.

    Click on GO ADVANCED and then scroll down to Manage Attachments to open the upload window.

  7. #7
    Registered User
    Join Date
    05-02-2020
    Location
    Vancouver, Canada
    MS-Off Ver
    Office 2019
    Posts
    68

    Re: Find range of text, parse and copy (for..each?) rows until next range found

    Here's the .xlsm
    sheet 1 has the results and I added a sheet 2 with Level instead.
    Attached Files Attached Files

  8. #8
    Registered User
    Join Date
    05-02-2020
    Location
    Vancouver, Canada
    MS-Off Ver
    Office 2019
    Posts
    68

    Re: Find range of text, parse and copy (for..each?) rows until next range found

    Sorry. I must have messed something up. My old file was .xlsx, so I saved as .xlsm and it went all odd.
    I reopened the .xlsx, added your code again, saved as a a different .xlsm and it works as it did the first time.

  9. #9
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,525

    Re: Find range of text, parse and copy (for..each?) rows until next range found

    Is "Level" only the possible word begin with "L"?
    Try change
    Please Login or Register  to view this content.
    to
    Please Login or Register  to view this content.

  10. #10
    Registered User
    Join Date
    05-02-2020
    Location
    Vancouver, Canada
    MS-Off Ver
    Office 2019
    Posts
    68

    Re: Find range of text, parse and copy (for..each?) rows until next range found

    odd results with the
    Please Login or Register  to view this content.
    replacement

    But yes, "Level" would be the only L related word. I figure there's a change a code may come through one day with an L starting it, but never the word level.
    Last edited by purgamentum; 05-07-2020 at 12:55 AM.

  11. #11
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,525

    Re: Find range of text, parse and copy (for..each?) rows until next range found

    Do you want to include any word begin with "L" as a header line?

  12. #12
    Registered User
    Join Date
    05-02-2020
    Location
    Vancouver, Canada
    MS-Off Ver
    Office 2019
    Posts
    68

    Re: Find range of text, parse and copy (for..each?) rows until next range found

    Negative, just Level

  13. #13
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,525

    Re: Find range of text, parse and copy (for..each?) rows until next range found

    So "L" and "Level"?

  14. #14
    Registered User
    Join Date
    05-02-2020
    Location
    Vancouver, Canada
    MS-Off Ver
    Office 2019
    Posts
    68

    Re: Find range of text, parse and copy (for..each?) rows until next range found

    No, just Level .. I'll have the other program switch the "L" to "Level"

  15. #15
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,525

    Re: Find range of text, parse and copy (for..each?) rows until next range found

    That's confusing, your workbook has "L" and "Level".

  16. #16
    Registered User
    Join Date
    05-02-2020
    Location
    Vancouver, Canada
    MS-Off Ver
    Office 2019
    Posts
    68

    Re: Find range of text, parse and copy (for..each?) rows until next range found

    Quote Originally Posted by jindon View Post
    That's confusing, your workbook has "L" and "Level".
    Sorry! I was goofing around with the cells on other sheets I deleted. Trying to do what your code does.
    my best effort was craziness like this:
    Please Login or Register  to view this content.

  17. #17
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,525

    Re: Find range of text, parse and copy (for..each?) rows until next range found

    I just need exact data and exact desired result in workbook showing the logic behind it.

  18. #18
    Registered User
    Join Date
    05-02-2020
    Location
    Vancouver, Canada
    MS-Off Ver
    Office 2019
    Posts
    68

    Re: Find range of text, parse and copy (for..each?) rows until next range found

    ok, new workbook attached. sheet1 is what I have and sheet2 is the desired results.
    Attached Files Attached Files

  19. #19
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,525

    Re: Find range of text, parse and copy (for..each?) rows until next range found

    OK, "Level" instead of just "L"...
    You can now change such word to suite.
    Please Login or Register  to view this content.

  20. #20
    Registered User
    Join Date
    05-02-2020
    Location
    Vancouver, Canada
    MS-Off Ver
    Office 2019
    Posts
    68

    Re: Find range of text, parse and copy (for..each?) rows until next range found

    Can it skip levels? there's no 24 to 39, or 44 to 47; and 48 is missing.

  21. #21
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,525

    Re: Find range of text, parse and copy (for..each?) rows until next range found

    OK, I see what you mean.. my assumption was wrong...

  22. #22
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,525

    Re: Find range of text, parse and copy (for..each?) rows until next range found

    Try this one
    Please Login or Register  to view this content.

  23. #23
    Registered User
    Join Date
    05-02-2020
    Location
    Vancouver, Canada
    MS-Off Ver
    Office 2019
    Posts
    68

    Re: Find range of text, parse and copy (for..each?) rows until next range found

    Perfect! Thank you jindon!

  24. #24
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,525

    Re: Find range of text, parse and copy (for..each?) rows until next range found

    You are welcome.

  25. #25
    Valued Forum Contributor
    Join Date
    11-04-2018
    Location
    Denpasar
    MS-Off Ver
    Excel 2010
    Posts
    777

    Re: Find range of text, parse and copy (for..each?) rows until next range found

    @jindon,

    I want to learn your codes, will it be OK to ask them here ?
    Or would it be better I open a new thread to ask about your codes ?

  26. #26
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,525

    Re: Find range of text, parse and copy (for..each?) rows until next range found

    You can ask here, but I'm out at the moment.
    So, my reply will be after 2,3 hours from now.

  27. #27
    Valued Forum Contributor
    Join Date
    11-04-2018
    Location
    Denpasar
    MS-Off Ver
    Excel 2010
    Posts
    777

    Re: Find range of text, parse and copy (for..each?) rows until next range found

    Thank you, Jindon.
    Take your time to reply, no need to hurry .

    I will ask your code on #2.

    Please Login or Register  to view this content.
    I see in the local windows that the last of a is a(39,1) with Empty value because cell A39 is blank.
    If I change (2) to (1) (or when I remove the "(2)"), in the local windows the last one is a(38,1) with the value of cell A38.

    1. I wonder why it needs (2) ?

    Please Login or Register  to view this content.
    2. would you please explain what the line above do ?
    What I can guess is only the if(left(a1:a10000,1)="L" which is :
    if the first character in any cell within cell A1 to A10000 is "L".....
    and this line is to get in what row where the cell first character value is "L",

    but how does the code work, I don't understand at all,
    I even don't understand what does the "[ ... ]" sign means, have tried to google it but can't find the result


    Please Login or Register  to view this content.
    When I see the local window, my guess, this line is to get how many times of "L" will be written.
    Assuming my guess is correct, I don't understand ...
    3. why it needs "+ 1" ?

    I want to understand those three lines first, the rest is later.

    Thank you, Jindon.
    Last edited by karmapala; 05-07-2020 at 03:36 AM.

  28. #28
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,525

    Re: Find range of text, parse and copy (for..each?) rows until next range found

    1)
    Please Login or Register  to view this content.
    [] are the short cut notation of Evaluate method.
    It calculates the formula in the brackets and return the value or an array as a result depends on how you write the formula.
    So, x will be the array that holds the row references that the cell in col.A begin with an "L".
    Since above row references are the row of "L", loop needs to set one row below "L" to one row above next "L" row.
    Therefore we need to add one row below the last cell of the data set to get last "Next" "L", so that actual last row of "L" can be calculated.

    2)
    Under above reason, need to expand the data range up to one row below the actual data range, otherwise it errors "Out of Range".

    3)
    That was how I first assumed the logic, so the latest code doesn't have that line.

  29. #29
    Valued Forum Contributor
    Join Date
    11-04-2018
    Location
    Denpasar
    MS-Off Ver
    Excel 2010
    Posts
    777

    Re: Find range of text, parse and copy (for..each?) rows until next range found

    @Jindon,

    Thank you very much for the explanation.
    Now I'm starting to play around with your code by trying to separate it little by little to see what is the result.

    For example, when I do this :
    Please Login or Register  to view this content.
    I see that the result of x is the row number value if the first char is "L" and FALSE value if the first char is not "L"

    Now with your complete code :
    Please Login or Register  to view this content.
    I think it filter out the FALSE value, and now I'm a bit clear on how the code works
    and now I understand what you mean in your sentence :
    x will be the array that holds the row references that the cell in col.A begin with an "L".
    .

    Since above row references are the row of "L", loop needs to set one row below "L" to one row above next "L" row.
    Therefore we need to add one row below the last cell of the data set to get last "Next" "L", so that actual last row of "L" can be calculated.

    2)
    Under above reason, need to expand the data range up to one row below the actual data range, otherwise it errors "Out of Range".
    Thank you very much for the explanation about this.

    That's all for the time being.
    I hope you don't mind if later I ask another question after I continue to learn your next lines but don't understand it.

    regards.
    Last edited by karmapala; 05-07-2020 at 05:56 AM.

  30. #30
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,525

    Re: Find range of text, parse and copy (for..each?) rows until next range found

    It is very important to understand the code given.
    Most of the cases, no one ask the details, but just ask to add the explanation for each line.
    That's useless and I believe most of the people don't mind reading the comments anyway.

    If you ask how you are asking, debugging for yourself with Local Window open, it will so helpful and I can feel that you are getting better understanding.
    You can ask anytime and I will respond as long as I can.

  31. #31
    Valued Forum Contributor
    Join Date
    11-04-2018
    Location
    Denpasar
    MS-Off Ver
    Excel 2010
    Posts
    777

    Re: Find range of text, parse and copy (for..each?) rows until next range found

    Yes, I learn so much from you specifically and from this forum generally.
    Sometimes when I see your code here and there, it made my headache, but it's so interesting for me to learn .

    And yes, I get better understanding than before.

    Thank you once again, Jindon.
    I repeat a comment from one of the member I read about you : "you are rock" .

  32. #32
    Registered User
    Join Date
    05-02-2020
    Location
    Vancouver, Canada
    MS-Off Ver
    Office 2019
    Posts
    68

    Re: Find range of text, parse and copy (for..each?) rows until next range found

    hi Jindon .. I looked over a ridiculous goof-up on my request. As Karmapala said above, your code is astounding to see and when I saw and tested your first post I totally forgot a major point.

    You'd placed the results in column C; whereas I was hoping for a new sheet. Reason being, in reducing my excel sheet to a sample sheet I took everything out of all the other columns since they were irrelevant (almost ?! ) to the code I was hoping for.
    Except that I was needing the row copied, not just the cell! I feel like a fool ... could you please adjust so that it'll copy the rows with all their content to a new sheet?

    Attached a final sheet.

    Please please
    Attached Files Attached Files

  33. #33
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,525

    Re: Find range of text, parse and copy (for..each?) rows until next range found

    Quote Originally Posted by purgamentum View Post
    As Karmapala said above
    OOps now I realise that it was not you asking about the details of the codes.
    Sorry for interrupting your thread, but I hope it also helped you to understand better...

    Try this.
    Please Login or Register  to view this content.

  34. #34
    Registered User
    Join Date
    05-02-2020
    Location
    Vancouver, Canada
    MS-Off Ver
    Office 2019
    Posts
    68

    Re: Find range of text, parse and copy (for..each?) rows until next range found

    Quote Originally Posted by jindon View Post
    OOps now I realise that it was not you asking about the details of the codes.
    Sorry for interrupting your thread, but I hope it also helped you to understand better...

    Try this.
    Works great, thank you again!
    Also, don't mind at all about the coding questions. Yes, I did read trying to follow along!

+ 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] Find substring in range and categorise cells in range based on substring found
    By Stavrosis in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 03-15-2020, 11:50 AM
  2. [SOLVED] find a range to insert a formula and copy it across for new rows
    By Ramzes in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 08-18-2017, 07:35 AM
  3. Find a string in specified cell range if found copy the cell
    By aykuncetinkaya in forum Excel Formulas & Functions
    Replies: 6
    Last Post: 11-03-2014, 06:12 PM
  4. [SOLVED] How to find text then select RANGE form the text found to lastrow of Column J
    By tuongtu3 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 10-23-2014, 02:45 AM
  5. [SOLVED] To Find every instance of TEXT copy, repeat until no Find found
    By DadaaP in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 07-25-2013, 02:15 PM
  6. [SOLVED] Find cell in Range and If found then copy to next sheet
    By Sachy in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 03-20-2013, 10:56 AM
  7. .Find problem when the found range's rows go from single to double digits
    By alsega in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 02-13-2012, 11: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