I'm encountering an odd VBA subscript out of range error in this simple sub :
Sub writeTypes(ByVal rowNb As Long, ByVal colNb, ws As Worksheet)
On Error GoTo ErrorHandler_ObjMethod
Const METHOD_NAME = "writeTypes (CCase)"
With ws
If Not isArrayEmpty(pTypes) Then
For i = LBound(pTypes) To UBound(pTypes)
If pTypes(i) <> "" Then
.Cells(rowNb, colNb).Value = .Cells(rowNb, colNb).Value & pTypes(i) & ";"
ElseIf i = UBound(pTypes) Then
.Cells(rowNb, colNb).Value = Left(.Cells(rowNb, colNb).Value, Len(.Cells(rowNb, colNb).Value) - 1)
End If
Next i
Else: .Cells(rowNb, colNb).Value = "N/A"
End If
End With
ErrorHandler_ObjMethod:
If err.Number <> 0 Then
Workbooks(AA_RESOURCES_WB).Close SaveChanges:=True
MsgBox (METHOD_NAME & vbNewLine & err.Number & vbNewLine & err.description)
End
End If
End Sub
The calling line of this procedure is : pUnassignedCases(i).writeTypes j, 7, ws
(The variables passed as params are correct I made sure of that several times)
Here is what I already tried to do :
-To remove the "ByVal"s in the parameters
-To remove the first "If Not"
-To remove the "Elseif" block
The removals were done properly without any syntax/logic errors.
I also checked any used variables (including the array of string that is "pTypes") in any way possible. All things seem perfectly fine.
I also tried to incorporate this code directly into my other sub (that goes through an array of CCase objects with a For loop) rather than calling it through a CCase object procedure, and somehow it works for the firsts CCases objects and then forces the loop to go beyond the CCase array upper bound... I can't make any sense of this.
When I go through the code line by line, the error occurs at the "End sub" line. But when I remove the error handling it goes fine but somehow the error gets passed on somewhere else in the code that isn't in anyway related to this sub and was working perfectly before... Then if I simply remove any calling of this sub everything is working as it already was.
Plus even when the error occurs, my worksheet line is still well updated with "N/A" (as it's supposed too because none of my cases objects have types for now). It's like the sub is cursed. This is driving me crazy.