PDA

View Full Version : cant figure out compile error: do without loop



tzexu1610
06-04-2018, 08:16 PM
Hi guys,

I can't figure out where is the do - loop error im having... my code is as follows




Sub round()


Application.ScreenUpdating = False
Application.DisplayStatusBar = False


Dim i As Integer
Dim j As Integer
Dim a As Integer
Dim b As Integer


a = 2
b = -2
i = 10 'start row
j = -2 'start column


'heading


Do Until Cells(a, b).value = ""


If Cells(a, b).value = "Ag (Silver)" Then 'header start

i = 10
j = j + 4
b = b + 4


Do


If IsNumeric(Cells(i, j).value) = True Then '1 dec place


Call Dec_places(Cells(i, j).value, 1)


Else


i = i + 1


End If


Loop Until Cells(i, j + 1).value = ""


Else


Do


If IsNumeric(Cells(i, j).value) = True Then '0 dec place


Call Dec_places(Cells(i, j).value, 0)


Else


i = i + 1


End If


Loop Until Cells(i, j + 1).value = ""



End If


Application.ScreenUpdating = True
Application.DisplayStatusBar = True


End Sub



Thanks in advance

p45cal
06-05-2018, 01:20 AM
Difficult to say when we don't know what you're trying to do, but try adding Loop directly before the line Application.ScreenUpdating = True.
There'll be other problems though; Do Until Cells(a, b).Value = "" refers to an impossible cell when b is -2!

Paul_Hossler
06-05-2018, 06:20 AM
Reformatting to indent and remove the extra blank lines so I can see the structure better, I'd say that the error message "Do without Loop' is correct

You forgot the Loop that goes with


Do Until Cells(a, b).Value = ""




Option Explicit
Sub round()

Application.ScreenUpdating = False
Application.DisplayStatusBar = False
Dim i As Integer
Dim j As Integer
Dim a As Integer
Dim b As Integer

a = 2
b = -2
i = 10 'start row
j = -2 'start column

'heading
Do Until Cells(a, b).Value = "" '---------------------- ONE START
If Cells(a, b).Value = "Ag (Silver)" Then 'header start

i = 10
j = j + 4
b = b + 4

Do '-----------------------TWO START
If IsNumeric(Cells(i, j).Value) = True Then '1 dec place
Call Dec_places(Cells(i, j).Value, 1)
Else
i = i + 1
End If
Loop Until Cells(i, j + 1).Value = "" '---------------------TWO END

Else
Do '---------------------THREE START
If IsNumeric(Cells(i, j).Value) = True Then '0 dec place
Call Dec_places(Cells(i, j).Value, 0)
Else
i = i + 1
End If

Loop Until Cells(i, j + 1).Value = "" '------------------THREE END
End If
Loop '<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< ONE END MISSING

Application.ScreenUpdating = True
Application.DisplayStatusBar = True
End Sub