+ Reply to Thread
Results 1 to 4 of 4

Do without Loop Error.... please help...

Hybrid View

  1. #1
    Registered User
    Join Date
    12-19-2018
    Location
    Europe
    MS-Off Ver
    2018
    Posts
    2

    Question Do without Loop Error.... please help...

    I have been trying to resolve this issue but no success. Everytime I tried to run the code it gives Bach "Do without Loop" error. I checked the codes and so far no luck in finding the error. I have Do and End If on every statements so I am not sure anymore what is the problem. Please help. Thank you.

    Sub Calculation
    Dim Row  As Integer
    Dim endLine As Long, hundert As Double, startDate As Variant, endDate As Variant, currDate As Date
    Row = 5
    Do While Cells(Row, 5) <> ""
    endLine = Cells(Rows.Count, 1).End(x1Up).Row
    wTime = 0
    tempWNum = -1
    Range("L" & Row & ":V" & endLine).Clear
    Call GroupTimes(Rows, endLine)
    
    Do Until endLine < Row
        startDate = Cells(Row, 8)
        endDate = Cells(Row, 9)
        dTime = (endDate - startDate) * 24
        currDate = Cells(Row, 1).Value2
        entryState = Cells(Row, 6).Value2
        
        If entryState = "Sick" Then
            Cells(Row, 17) = dTime
            GoTo ContinueDo
        End If
    
        If entryState = "Vacation" Then
            Cells(Row, 18) = dTime
            GoTo ContinueDo
        End If
    
        If entryState = "ZA" Then
            Cells(Row, 19) = dTime
            GoTo ContinueDo
        End If
    
        wTime = wTime + dTime
    
        If Not IsEmpty(Cells(Row, 1).Value2) Then
            wnum = IsoWeekNumber(currDate)
        End If
        If tempWNum < 0 Then
            tempWNum = wnum
        End If
    
        If wnum > tempWNum Then
            wTime = wTime - dTime
            Cells(Row - 1, 21) = wTime
            wTime = dTime
            tempWNum = wnum
        End If
    
        If IsEmpty(startDate) Or IsEmpty(endDate) Then
            GoTo ContinueDo
        End If
        If Not Weekday(Cells(Row, 1)) = 1 Then
        hundert = GetTimeHundertPerc(startDate, endDate)
        End If
        If hundert > 0 Then
            conv = hundert * 24
            Cells(Row, 16) = conv
            dTime = dTime - conv
            hundert = 0
        End If
    
        If Weekday(Cells(Row, 1)) = 1 Then
            Cells(Row, 16) = dTime
        Else
            If dTime > 0 Then
                If dTime <= 8 Then
                    Cells(Row, 14) = dTime
                Else
                    If (dTime - 8) > 0 Then
                        Cells(Row, 14) = 8
                        Cells(Row, 15) = dTime - 8
                    End If
                End If
            End If
        End If
        startDate = Cells(Row, 8)
    ContinueDo:
         Row = Row + 1
         Loop
    'write last week time
    Cells(Row - 1, 21) = wTime
    
    End Sub
    Last edited by jazzyred79; 12-19-2018 at 05:44 AM.

  2. #2
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: Do without Loop Error.... please help...

    Hi and welcome to the forum. Unfortunately your post does not comply with Rule 2 of our Forum RULES. Use code tags around code.

    Posting code between [CODE] [/CODE] tags makes your code much easier to read and copy for testing, it also maintains VBA formatting.

    Click on Edit to open your thread, then highlight your code and click the # icon at the top of your post window. More information about these and other tags can be found here

    In addition you need to tell us what your 'issue' is with the code. You can't expect us to guess.
    Richard Buttrey

    RIP - d. 06/10/2022

    If any of the responses have helped then please consider rating them by clicking the small star icon below the post.

  3. #3
    Valued Forum Contributor mohan.r1980's Avatar
    Join Date
    09-18-2010
    Location
    Mumbai, India
    MS-Off Ver
    Excel 2010 (windows7)
    Posts
    729

    Re: Do without Loop Error.... please help...

    Edit Your post select your code and hit # button for Code Tag.

    In your code there is lot of if condition do you know which End if belonging to which if?

    there is two "Do While" but ther is only one "Loop" and One Loop word Missing

    tabing code is best for understand

    here is your code

    Sub Calculation()
    Dim Row As Integer
    Dim endLine As Long, hundert As Double, startDate As Variant, endDate As Variant, currDate As Date
    Row = 5
    
    Do While Cells(Row, 5) <> ""
    endLine = Cells(Rows.Count, 1).End(x1Up).Row
    wTime = 0
    tempWNum = -1
    Range("L" & Row & ":V" & endLine).Clear
    Call GroupTimes(Rows, endLine)
    
            Do Until endLine < Row '------------------Missing Loop
            startDate = Cells(Row, 8)
            endDate = Cells(Row, 9)
            dTime = (endDate - startDate) * 24
            currDate = Cells(Row, 1).Value2
            entryState = Cells(Row, 6).Value2
    
    If entryState = "Sick" Then
        Cells(Row, 17) = dTime
        GoTo ContinueDo
    End If
    
    If entryState = "Vacation" Then
        Cells(Row, 18) = dTime
        GoTo ContinueDo
    End If
    
    If entryState = "ZA" Then
        Cells(Row, 19) = dTime
        GoTo ContinueDo
    End If
    
    wTime = wTime + dTime
    
    If Not IsEmpty(Cells(Row, 1).Value2) Then
        wnum = IsoWeekNumber(currDate)
    End If
    If tempWNum < 0 Then
        tempWNum = wnum
    End If
    
    If wnum > tempWNum Then
        wTime = wTime - dTime
        Cells(Row - 1, 21) = wTime
        wTime = dTime
        tempWNum = wnum
    End If
    
    If IsEmpty(startDate) Or IsEmpty(endDate) Then
        GoTo ContinueDo
    End If
    
    If Not Weekday(Cells(Row, 1)) = 1 Then
        hundert = GetTimeHundertPerc(startDate, endDate)
    End If
    
    If hundert > 0 Then
        conv = hundert * 24
        Cells(Row, 16) = conv
        dTime = dTime - conv
        hundert = 0
    End If
    
    If Weekday(Cells(Row, 1)) = 1 Then
        Cells(Row, 16) = dTime
    Else
        If dTime > 0 Then
            If dTime <= 8 Then
                Cells(Row, 14) = dTime
            Else
                If (dTime - 8) > 0 Then
                    Cells(Row, 14) = 8
                    Cells(Row, 15) = dTime - 8
                End If
            End If
        End If
    End If
    startDate = Cells(Row, 8)
    ContinueDo:
    Row = Row + 1
    Loop
    'write last week time
    Cells(Row - 1, 21) = wTime
    
    End Sub
    Regards,
    MohanS


    "Perfection is not attainable, but if we chase perfection we can catch excellence." - Vince Lombardi

    You can simply say thanks by clicking "*Add Reputation" icon

  4. #4
    Registered User
    Join Date
    12-19-2018
    Location
    Europe
    MS-Off Ver
    2018
    Posts
    2

    Re: Do without Loop Error.... please help...

    Thank you all so much for your replies!

+ 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] Excel VBA - Loop through recordsets ADODB with For Loop Error - Help
    By ironfelix717 in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 08-27-2018, 08:44 AM
  2. trying to copy a worksheet to end gives error and I get stuck in a error loop
    By pongmeister in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 08-11-2017, 11:48 AM
  3. Replies: 5
    Last Post: 12-08-2016, 06:43 PM
  4. [SOLVED] Go to next loop iteration if current loop has error
    By luv2glyd in forum Excel Programming / VBA / Macros
    Replies: 15
    Last Post: 02-03-2016, 09:54 PM
  5. Loop Nesting is returning Run-Time Error '-2147221080 (800401a8)': Automation Error
    By ChristopherBrandonKi in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 11-21-2014, 02:36 PM
  6. HOW TO: Pause loop, fix error on a popup UserForm, continue loop
    By AndyMachin in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 06-19-2014, 04:37 PM
  7. Nesting a loop within a loop error
    By PunPryde in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 02-17-2011, 08:07 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