I have code that creates an array and enters "supplier names" or "null" (actual string null) into an array if certain conditions are met. If certain conditions are not met, the array will not be filled with any data and is thus empty (or so I believe).
The next thing I want to do is print out only the supplier names listed in that array. Hence I have to create an If
statement that will only be entered when the item in the array does not have the value "null" and when the array is not empty.
I'm experiencing the following problem in the code below. The string array supplierCategoryP(r)
did not meet the conditions and thus was never filled with any information. So I assume this is an empty array. Yet when I debug, the code shows that this first If
is still entered:
If supplierCategoryP(r) <> "null" And Not IsEmpty(supplierCategoryP(r)) Then
...while it shouldn't, since the array is empty.
k = 1
If countNoNull > 0 Then
moveDownBy = countNoNull
For r = 1 To nP
If supplierCategoryP(r) <> "null" And Not IsEmpty(supplierCategoryP(r)) Then
Cells(9 + k + moveDownBy, 5) = supplierCategoryP(r)
k = k + 1
countNoNull = countNoNull + 1
End If
Next r
Else
For r = 1 To nP
If supplierCategoryP(r) <> "null" And Not IsEmpty(supplierCategoryP(r)) Then
Cells(9 + k, 5) = supplierCategoryP(r)
k = k + 1
countNoNull = countNoNull + 1
End If
Next r
End If
Code that creates the array:
Worksheets("PEMCO").Activate
comNO = CLng(Range("commoditiesAmount").Text)
nP = CLng(Range("supplierAmount").Text)
ReDim supplierCategoryP(1 To nP) As String
For c = 1 To comNO
commodityLoop = Cells(3, 1 + c)
If commodity = commodityLoop Then
For r = 1 To nP
cellX = Cells(3 + r, 1 + c)
If cellX = "x" Then
supplierCategoryP(r) = Cells(3 + r, 1)
Else
supplierCategoryP(r) = "null"
End If
Next r
End If
Next c