I have a macro which runs almost how I want it to:
The macro populates strings based on the contents of a combination of cells.
The inputs are ranges which I convert to arrays. Column E3 has values in cells starting at row 3 and below.
With ActiveWorkbook.Worksheets("Sheet2")
Set GclR = .Range("E3", .Range("E3").End(xlDown))
End With
GclArr = GclR.Value
The arrays vary in size from non-existent to half a dozen rows in length. My code loops through the contents and finds each value and places it into it's respective position in a string.
Where it trips up is when when I have less than 2 values in the array. Excel hangs and crashes.
I figure this is due to the For Loop:
If GclArr(1, 1) <> 0 Then
If Gcl <> 0 Then
For R = 1 To UBound(GclArr, 1)
GclStr = GclStr & GclArr(R, 1) & " " & Gcl & " "
Next R
End If
End If
If R = 1 and UBound(GclArr, 1) also = 1, it seems the For Loop gets confused. (It works perfectly if UBound is 2 or greater).
I used an If statement to handle the case when the array is empty, but can't think of a way to get this to work for an array with a single value.
What other function can I use to achieve the same result, but with the ability to handle single values in arrays?
For R = LBound(GclArr)?