none
'Do unitl' loop in VBA RRS feed

  • Question

  • c = 1
    Do Until c > 89
         IERM = Worksheets(ShtName).Cells(4, 185 + c).Value
         IFRM = Worksheets("Input Exporter").Cells(3, 185 + c).Value
                
                If IFRM <> "" Then
                    
                    CODE
    
                    Else: GoTo EndLoop3
                End If
    
    EndLoop3:
    
                c = c + 1
    
    Loop

    (IERM and IFRM and c have been declared)

    I've been asked to look at some code and noticed something about this loop while debugging. I observed the following runtime error message while pressing the F8 button repeatedly

    "Application-defined or object defined error" - Why does this appear?

    Plus there's something about the whole loop structire which  seems kinda off to me?

    Monday, October 24, 2016 1:48 PM

All replies

  • There is nothing wrong with the code. You don't really need the EndLoop3 (or the Else: GoTo....) unless it is used within CODE.
    Monday, October 24, 2016 3:32 PM
  • Have you declared ShtName variable? May be missing
    Sunday, October 30, 2016 5:26 AM
  • Have you declared ShtName variable? May be missing

    yeah but its been done like this

    Dim ShtName$

    Tuesday, November 1, 2016 9:09 AM
  • First of all,

    What is the use of Else and GoTo Statement here because it can be done simply like this:

    c = 1 Do Until c > 89 IERM = Worksheets(ShtName).Cells(4, 185 + c).Value IFRM = Worksheets("Input Exporter").Cells(3, 185 + c).Value If IFRM <> "" Then CODE

    End If c = c + 1 Loop

    In the above code there is not problem of declaration. Please check the variable name ShtName has a valid sheet name which exists in the workbook?


    Vish Mishra

    Tuesday, November 1, 2016 11:52 AM
  • Hi,

    If your question is answered kindly mark them answered here. This will help in maintaining this forum neat.


    Vish Mishra

    Monday, November 7, 2016 11:49 AM