title: Excel VBA loop and get value from an array
body: <p>I have the following code to retrieve a selection then making it a array of string.</p>
  
  <pre><code>Dim strArgument As Variant
  Dim irange As Range
  Dim ricosString As Variant
  
  Set irange = Selection
  ricosString = RangeToStringArray(irange)
  
  Dim vArray As Variant
  For i = LBound(ricosString) To UBound(ricosString)
      Set vArray = ricosString(i)
  </code></pre>
  
  <p>My problem here is on the <code>ricosString(i)</code>. It is throwing an error <code>Subscript out of range.</code> Any ideas why?</p>
  
  <p>Here is the code for <code>RangeToStringArray</code></p>
  
  <pre><code>Public Function RangeToStringArray(theRange As Excel.Range) As String()
  
  Dim variantValues As Variant
  variantValues = theRange.Value
  
  Dim stringValues() As String
  ReDim stringValues(1 To UBound(variantValues, 1), 1 To UBound(variantValues, 2))
  
  Dim columnCounter As Long, rowCounter As Long
  For rowCounter = UBound(variantValues, 1) To 1 Step -1
     For columnCounter = UBound(variantValues, 2) To 1 Step -1
         stringValues(rowCounter, columnCounter) = CStr(variantValues(rowCounter, columnCounter))
     Next columnCounter
  Next rowCounter
  
  RangeToStringArray = stringValues
  </code></pre>
  
  <p>End Function</p>