Hello all
I have a procedure which creates an array based upon values in a named
range. There's three possible ranges which can be selected. The first
two ranges contain more than one value, whereas my third only contains
one item.
I create the array as follows. (The gstrReportingArea variable relates
to one of the three possible ranges, and mwshtVariablesConstants is a
worksheet object variable).
Public gaFactoryAreas() As String
'Create variable array to hold factory areas
c = mwshtVariablesConstants.Range("var" & gstrReportingArea &
"_FactoryAreas").Columns.Count
ReDim gaFactoryAreas(1 To c)
For i = 1 To c
gaFactoryAreas(i) = mwshtVariablesConstants.Range("var" &
gstrReportingArea & "_FactoryAreas").Cells(1, i)
Next i
My problem relates to when I try to use gaFactoryAreas array in a 'For
Each' loop.
When I have only one item in gaFactoryAreas, the loop fails, whereas if
there's more than one item it fails.
Does anyone have any suggestions on how to deal with the possibility
that there may only be one item in an array. I'"m trying to avoid using
lots of IF statements.
Regards
Bookmarks