+ Reply to Thread
Results 1 to 10 of 10

Loop is skipping iterations

  1. #1
    Registered User
    Join Date
    08-17-2012
    Location
    Serbia
    MS-Off Ver
    Excel 2010
    Posts
    85

    Loop is skipping iterations

    I am new to loops but it seems that I can not avoid them forever.
    I've modified macro from the web that suits my needs but in my case it doesn't work properly.

    Please Login or Register  to view this content.
    Where l = is counta function to count number of iterations for every case
    counter = should be number in cell "A13" from 1 to l (this number represent row number
    so when changes from 1 to l it calls NalogADD which basically copies range (that is dependent of counter
    number-match index function).

    Range (NalogADD) is copied in first empty cell and so on.
    After review of whole operation, not all instances are activated/copied(e.g.2-4, 5...missing) also instances
    (copied ranges) are mixed (last is copiedfirst, then first, then 6th...).

    I hope that I've explained this properly.
    Last edited by Jovica; 02-22-2014 at 06:50 AM.

  2. #2
    Forum Expert
    Join Date
    02-11-2014
    Location
    New York
    MS-Off Ver
    Excel 365 (Windows)
    Posts
    5,957

    Re: Loop is skipping iterations

    I hope that I've explained this properly.
    No - you need to post the formulas from B1 and A13, and the code in the macro NalogADD

  3. #3
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Loop is skipping iterations

    What do you see in the Immediate Window (CTRL+G) if you add this inside the loop.
    Please Login or Register  to view this content.
    Any 'jumps' in the value of i?
    If posting code please use code tags, see here.

  4. #4
    Registered User
    Join Date
    08-17-2012
    Location
    Serbia
    MS-Off Ver
    Excel 2010
    Posts
    85

    Re: Loop is skipping iterations

    @Norie
    It happens so fast I am not able to see anything.
    But when I change "l" in For i = 1 To l to 3 (For i = 1 To 3 <--was 39), there is still a gap in values (still missing values for 2 and 3).

    File uploaded :
    T-Upload.xlsm

    @Bernie Deitrick
    You wrote that without reading my question?
    Set l = ws.Range("b1") so "B1" value is countA
    counter = should be a number in cell "A13" from 1 to l
    Last edited by Jovica; 02-20-2014 at 03:39 AM.

  5. #5
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Loop is skipping iterations

    Jovica

    Look at the Immediate Window after the code has run

  6. #6
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Loop is skipping iterations

    Accidental duplicate.

  7. #7
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Loop is skipping iterations

    Why do you think iterations are being skipped?

    I've just stepped through the code and that's just not happening.

  8. #8
    Registered User
    Join Date
    08-17-2012
    Location
    Serbia
    MS-Off Ver
    Excel 2010
    Posts
    85

    Re: Loop is skipping iterations

    Please start macro TRANSF. Data from sheet "KALKGL" is being generated in Sheet "JUNK"Range (B13:N15), dependant of JUNK A13 (A13 is number of KALGL row, so it should go from 1 to 39 in this case to cover all date from KALKGL). Every time I've started this macro Second row from KALKGL is skipped, process starts with last value (row-KALGL) not row 1, then data from row 2 is skipped, then from row 3, data from row 4 is there (NALOG-result sheet) and so on.

  9. #9
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,437

    Re: Loop is skipping iterations

    some debug you your routine will show what it is doing.
    Again the information will appear in the immediate window (CTRL+G in VBE to see it)

    Please Login or Register  to view this content.
    rows are skipped when A12 is not a valid that requires copying. Why that is I don't know as I don't understand what you are trying to do.
    Cheers
    Andy
    www.andypope.info

  10. #10
    Registered User
    Join Date
    08-17-2012
    Location
    Serbia
    MS-Off Ver
    Excel 2010
    Posts
    85

    Re: Loop is skipping iterations

    @Andy Pope Thanks. I didn't test A12, so problem was in A12. Since I don't know any other way to reset counter to 1 and avoid looping first value twice I've change it to :
    Please Login or Register  to view this content.
    Also put +1 in B1.

    What I am trying to do is automate process of putting invoices data into database.
    "JUNK"Range (B13:N15) generates data for every invoice (1 row in KALKGL is 1 invoice data) based on specific situation.
    Loop should put all that together and after that only thing that's left is to put all that to DBF file.

    Thanks guys for the 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. [SOLVED] For loop iterations - quick question
    By drinkmorewine in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 06-07-2013, 02:51 PM
  2. [SOLVED] Losing format information in For Loop iterations
    By GFIJames in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 08-24-2012, 11:17 AM
  3. VBA For loop where number of iterations can be changed from inside loop
    By barrboy89 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 05-11-2011, 12:18 PM
  4. [SOLVED] VBA | Individual Iterations faster than Loop Statement
    By Butaambala in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 07-03-2005, 08:05 AM
  5. Do loop skipping
    By medicenpringles in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 06-27-2005, 10:05 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