Hi,
I have macro problem "Run-time error '9' : Subscript out of range".
The macro works in some data, some data need macro changes, some data do not work at all.
The excel file in attachment. have 3 sheet, "Monday", "Tuesday" and "Friday".
1) Sheet "Monday" : Works with original macro ( no changes).
2) Sheet "Tuesday" : Works with changes
For i = 1 To UBound(a, 1)
to
For i = 1 To UBound(a, 1) - 1
3) Sheet "Friday" : Not work with original macro or changes.
What is macro do is finding number pattern of Plus-Zero-Minus (+0-) then assign "1" at the start of pattern.
The data, original macro and change macro included in file excel.
Excel File : https://www.mediafire.com/file/12p3t...acro.xlsb/file
Original Code:
Sub test_ori()
Dim a, b, i As Long, ii As Long
With Range("e3", Range("e" & Rows.Count).End(xlUp))
a = .Value: ReDim b(1 To UBound(a, 1), 1 To 1)
For i = 1 To UBound(a, 1)
If a(i, 1) > 0 Then
ii = 1
Do While a(i + ii, 1) = 0
ii = ii + 1
Loop
If (ii > 1) * (a(i + ii, 1) < 0) Then b(i, 1) = 1
i = i + ii - 1
End If
Next
.Columns(3) = b
End With
End Sub
Change Code:
Sub test_minus1()
Dim a, b, i As Long, ii As Long
With Range("e3", Range("e" & Rows.Count).End(xlUp))
a = .Value: ReDim b(1 To UBound(a, 1), 1 To 1)
For i = 1 To UBound(a, 1) - 1
If a(i, 1) > 0 Then
ii = 1
Do While a(i + ii, 1) = 0
ii = ii + 1
Loop
If (ii > 1) * (a(i + ii, 1) < 0) Then b(i, 1) = 1
i = i + ii - 1
End If
Next
.Columns(3) = b
End With
End Sub
Bookmarks