+ Reply to Thread
Results 1 to 11 of 11

Find function in nested loop breaking down - not on first time through loop

  1. #1
    Registered User
    Join Date
    08-30-2013
    Location
    United States
    MS-Off Ver
    Excel 2010
    Posts
    39

    Find function in nested loop breaking down - not on first time through loop

    I really appreciate the site's contributors' offering your experience and expertise.

    So, I am trying to perform a somewhat complex task with the loop(s) & If(s) below; to briefly describe: if a row's column L = "UE", then get the dollar amount in column T and find its negative equivalent in column T; If found, see if several other things match, and if they do then put a number in column 32. Seemed pretty simple to me starting out, but it got tricky for me..

    When I run the loop, on step #13 it comes back

    The excel file and the steps that the macro are trying to accomplish are attached.
    Attached Files Attached Files
    Last edited by adamstarr12; 10-12-2014 at 10:27 PM.

  2. #2
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: Find function in nested loop breaking down - not on first time through loop

    Hi adam

    Well, have to admit, you've got me a bit intrigued. I'm an old bean counter (CPA Retired). Have done thousands of reconciliations in over 35 years in the business.

    You posted quite a dissertation in your Word Document. What you didn't say is what works and what doesn't.

    From your Thread Title it appears things are going South in Step 13. Tell me a bit about yourself...and...tell me in your own words...what is Step 13 supposed to be doing?

    When it blows out in Step 13 these evaluate as follows:

    TCfind = ActiveCell.Offset(0, 8).Value2 evaluates to 0
    LCfind = ActiveCell.Offset(0, 10).Value2 evaluates to 0
    GCfind = ActiveCell.Offset(0, 12).Value2 evaluates to 0.02
    CurrentPC = ActiveCell.Offset(0, -6) evaluates to P3091
    CurrentRow = ActiveCell.Row evaluates to 27

    So, what are we doing with this information?
    John

    If you have issues with Code I've provided, I appreciate your feedback.

    In the event Code provided resolves your issue, please mark your Thread as SOLVED.

    If you're satisfied by any members response to your issue please use the star icon at the lower left of their post.

  3. #3
    Registered User
    Join Date
    08-30-2013
    Location
    United States
    MS-Off Ver
    Excel 2010
    Posts
    39

    Re: Find function in nested loop breaking down - not on first time through loop

    Hey John,

    Thank you for your time and interest! My story and task has remarkable parallels to your story; I am a "Bean Counter" (haha) and we recently did an accounting system "upgrade" and I am sorting through several accounts trying to label any entries that haven't been cleared yet (with the colors in the word doc).


    You have definitely pinpointed the problem I am having - in Step #13 (#14,etc haven't been tested). One thing I am trying right now: Before running the macro, rewrite the "PreviousMatch = MatchRow + 1" in step #13 to be "PreviousMatch = MatchRow", and then a different error comes up much later in the dataset (same loop).
    TCfind = ActiveCell.Offset(0, 8).Value2 evaluates to (13,221,361)
    LCfind = ActiveCell.Offset(0, 10).Value2 evaluates to (8,213,556)
    GCfind = ActiveCell.Offset(0, 12).Value2 evaluates to (13,221,261)
    CurrentPC = ActiveCell.Offset(0, -6) evaluates to P4209
    CurrentRow = ActiveCell.Row evaluates to 152
    Step 13 is trying to find two entries within the dataset that offset each other in all three currencies (TransactionC,LocalC,GroupC) - one with document type "UE" and the other "AB"; the entries must be within the same "profit center" (P****) and neither can have been identified as a match to any of the steps before 13 (so column "activecell.offset(0,20) = "" - in the If statement)

    I tried to set the loop up to find the number of offsetting TC amounts, then to search through each of those matches to see if the other criteria are matched as well.

    I've tried very hard to get this to work, and honestly believe I should pay someone for their efforts to have this work. Please let me know what you think Thanks John!

    Adam

  4. #4
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: Find function in nested loop breaking down - not on first time through loop

    Hi Adam

    Please give some examples of records in your Data File that would meet the test of Step 13. I looked and could not see anything obvious.

    Also, explain this Code
    Please Login or Register  to view this content.
    Should it not be
    Please Login or Register  to view this content.

  5. #5
    Registered User
    Join Date
    08-30-2013
    Location
    United States
    MS-Off Ver
    Excel 2010
    Posts
    39

    Re: Find function in nested loop breaking down - not on first time through loop

    Hey John,

    Unfortunately, I deleted a lot of the data when I was uploading the file here on the site, and there are no examples of "#13" left in the file; that defeats the purpose of the data set, I apologize. An example is: (with many columns deleted)
    Regarding whether the it should be "<>" or "<", I think it should be as it is because I only put that in there to prevent vba multiplying zero by -1. All other numbers should be multiplied by -1 though.

    Adam

  6. #6
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: Find function in nested loop breaking down - not on first time through loop

    Hi Adam

    I'll work with this with you if you'll incorporate the data into your example file. It's not possible to test otherwise.
    Last edited by jaslake; 10-12-2014 at 09:35 PM.

  7. #7
    Registered User
    Join Date
    08-30-2013
    Location
    United States
    MS-Off Ver
    Excel 2010
    Posts
    39

    Re: Find function in nested loop breaking down - not on first time through loop

    John,

    Thank you very much for working with me!

    I apologize - I didn't realize I could change my data that I originally uploaded. I changed the data around so that there are three matches now:The file above reflects these matches -(1) rows 158 & 153 (2) rows 149 & 187 (3) rows 195 & 220

    Adam
    Last edited by adamstarr12; 10-12-2014 at 10:49 PM.

  8. #8
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: Find function in nested loop breaking down - not on first time through loop

    Hi Adam

    I'm able to find only one matching Record in the Data File...Records 153 and 158. Records 149 and 187 have different Dollar Amounts. Records 195 and 220 are AO Records.

    There's two different versions of Step 13 Code in the attached. Try them both (one at a time of course)...they appear to give the same results.

    I've truncated your original Code to run only through Step 13. You can change that of course once Step 13 is performing as required.
    Attached Files Attached Files

  9. #9
    Registered User
    Join Date
    08-30-2013
    Location
    United States
    MS-Off Ver
    Excel 2010
    Posts
    39

    Re: Find function in nested loop breaking down - not on first time through loop

    Hey John,

    I really appreciate your time and expertise for making this work. The macro you assembled works seamlessly! I have one question though..

    The file I downloaded has the 'Old_Code' and 'New_Code', but also has some other macros that I'm not able to get rid of and seems engrained in vba - no matter where I go. Here is a screen shot of the extra macros:And when I try to delete it, I get this screen:These sort of things make me very uneasy; however, it may be due to my lack of understanding. Could you please explain what these macros are for and why I can't get rid of them?


    Again, thank you for your time.

    Adam

  10. #10
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: Find function in nested loop breaking down - not on first time through loop

    Hi Adam

    None of these three files are an issue. ATPVBAEN and FUNCRES are part of Analysis Toolpack Addin. Google on either of the File names to learn how to manage these Files.

    PERSONAL.XLSB was created either by you or someone who previously used your Computer. Google on the File name to learn how to manage it.

  11. #11
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: Find function in nested loop breaking down - not on first time through loop

    Hi Adam

    You're welcome...glad I could help.

    If you're satisfied by any members response to your issue please use the star icon at the lower left of their post.

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

+ 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. Find function in nested loop breaking down - not on first time through loop
    By adamstarr12 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 10-07-2014, 04:59 PM
  2. Next without For error in nested loop - Escaping a Nested Loop?
    By BeneRich in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 02-10-2012, 06:38 PM
  3. Breaking a Find Loop
    By Jmoo in forum Word Programming / VBA / Macros
    Replies: 1
    Last Post: 06-23-2010, 10:55 AM
  4. For each loop nested; getting stuck on one cell in first iteration of nested loop
    By Excel_vba in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 12-22-2009, 11:54 AM
  5. [SOLVED] Trying to execute function after negative if conditional nested in For each loop
    By Red in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 08-21-2006, 04:20 PM

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