Overflow error on VBA Module
Hello,
I have two VBA-Modules that are almost the same.
The first looks like this:
Code:
Sub Versuch()
Dim Z As Double
Dim counter As Integer
Dim a As Double
Dim b As Double
Dim f As Integer
Dim e As Integer
Dim WS_Count As Integer
Dim I As Integer
WS_Count = ActiveWorkbook.Worksheets.Count
For I = 1 To WS_Count
Worksheets(I).Select
counter = 10
Z = 1
a = Cells(8, 6).Value
b = Cells(9, 6).Value
f = Cells(3, 6).Value
e = Cells(4, 6).Value
Do Until Z > e
Cells(counter, 3).Value = Z
counter = counter + 1
If Z < f Then
Z = Z + a
End If
If Z >= f Then
Z = Z + b
End If
Loop
Next I
End Sub
The second one is slightly changed and gives me an overflow error because of the line: counter = counter +1
Code:
Sub twosignificantlayers()
Dim Z As Double
Dim counter As Integer
Dim a As Double
Dim b As Double
Dim f As Integer
Dim e As Integer
Dim WS_Count As Integer
Dim I As Integer
Dim secondlayer As Integer
Dim secondlayerstep As Integer
Dim secondtobottom As Integer
WS_Count = ActiveWorkbook.Worksheets.Count
For I = 1 To WS_Count
Worksheets(I).Select
counter = 10
Z = 1
a = Cells(8, 6).Value
b = Cells(9, 6).Value
f = Cells(3, 6).Value
e = Cells(4, 6).Value
secondlayer = Cells(5, 6).Value
secondlayerstep = Cells(11, 6).Value
secondtobottom = Cells(15, 6).Value
Do Until Z > e
Cells(counter, 3).Value = Z
counter = counter + 1
If Z < f Then
Z = Z + a
End If
If Z >= f And Z < secondlayer Then
Z = Z + secondlayerstep
End If
If Z >= secondlayer Then
Z = Z + secondtobottom
End If
Loop
Next I
End Sub
Can anyone tell me why I get this error? It seems like the programme is not jumping to the next worksheet to continue the calculation
Regards,
Franz