+ Reply to Thread
Results 1 to 7 of 7

Loop Execution--Questions

  1. #1
    Registered User
    Join Date
    06-27-2011
    Location
    United States
    MS-Off Ver
    Excel 2007
    Posts
    21

    Loop Execution--Questions

    Hey guys,

    Here is some background about me and this project I am working on. I am a college grad that just recieved his first position. My job is to go through this workbook that is broken from the database and begin rewriting some programming to make it automated again. I've reached my first stump, I hope you guys can help!


    The spreadsheet consist of the previous year's last quarter, and the current year's 4 quarters. The macros will take whatever is in the last column (Previous year's last quarter), copy it, and paste it into the correct column. Next, it would clear everything else. There is 4 different worksheets that it will automate through. For some reason, I keep getting inconsistant results with this macros and I cannot figure it out.

    Please Login or Register  to view this content.

    Any ideas? questions?
    Thanks!
    Last edited by VBNewb; 06-27-2011 at 01:04 PM.

  2. #2
    Forum Expert snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,649

    Re: Loop Execution not working correctly

    Maybe using the macrorecorder will result in less code than you have now.
    There's a lot of VBA basics (courses) on the Internet. Not indavisable to study those first.



  3. #3
    Registered User
    Join Date
    06-27-2011
    Location
    United States
    MS-Off Ver
    Excel 2007
    Posts
    21

    Re: Loop Execution--results not consistant after 1st loop.

    In addition, can anyone help me with this code. I dont quite understand what it does...


    First loop, endrow = nothing. Second loop endrow = "Title". Next, endrow = nothing thereafter.


    Please Login or Register  to view this content.
    Last edited by VBNewb; 06-27-2011 at 12:05 PM.

  4. #4
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259

    Re: Loop Execution--results not consistant after 1st loop.

    Hello VBNewb,

    Welcome to the Forum!

    In response to your first question, please define what you mean by "inconsistent".

    In response to the second question, the macro is performing a search loop using Find and FindNext. Find performs a one time search and is either successful or not. If it is successful then control is passed on to the Do ... Loop. Starting at the next cell after the last successful Find, FindNext will continue until either another instance is found or it returns back to the first find. The variable flg keeps track of the row where the first Find occurred.
    Sincerely,
    Leith Ross

    Remember To Do the Following....

    1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.
    2. Thank those who have helped you by clicking the Star below the post.
    3. Please mark your post [SOLVED] if it has been answered satisfactorily.


    Old Scottish Proverb...
    Luathaid gu deanamh maille! (Rushing causes delays!)

  5. #5
    Registered User
    Join Date
    06-27-2011
    Location
    United States
    MS-Off Ver
    Excel 2007
    Posts
    21

    Re: Loop Execution--results not consistant after 1st loop.

    Thank you Ross and snb for responding.

    By I "inconsistant", I was refering to why the varible "endrow" in the loop is either nothing or title. I misused the word, my apologies. I also apologizes beforehand for any terms I will be using incorrectly...

    As long as "endrow" is not nothing, the spreadsheet should clear the correct cells. Apparently, it is only clearing in the second "step" of the loop. I am wondering why.

    Can anyone shed some light on this:

    Please Login or Register  to view this content.

  6. #6
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259

    Re: Loop Execution--results not consistant after 1st loop.

    Hello VBNewb,

    This is the first Find. If successful it will return a reference to the cell where the value was found. The Set statement is used to assign an object to an object variable. In this case, the object variable is Endrow.

    If the search is successful Endrow will either be a reference to the cell or set to the special object variable Nothing. The IF statement checks if Find was successful or not and if not then the macro terminates.

  7. #7
    Registered User
    Join Date
    06-27-2011
    Location
    United States
    MS-Off Ver
    Excel 2007
    Posts
    21

    Re: Loop Execution--Questions

    thank you so much! It was balantly obviously. *facepalm*

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

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