Function Make1D(v As Variant, Optional iBase As Long = 0) As Double()
' Returns a 1D iBase-based array of the values in v, which can be a
' column or row vector range, a 1D or 2D array, or a scalar
Dim adOut() As Double
Dim rArea As Range
Dim cell As Range
Dim nOut As Long
Dim i As Long
If IsArray(v) Then
If TypeOf v Is Range Then
ReDim adOut(iBase To v.Cells.Count - 1 + iBase)
For Each rArea In v.Areas
For Each cell In rArea.Cells
If VarType(cell.Value2) = vbDouble Then
adOut(nOut + iBase) = CDbl(cell.Value2)
nOut = nOut + 1
Else
Err.Raise CVErr(xlErrValue)
End If
Next cell
Next rArea
Make1D = adOut
Else ' get the first column
ReDim adOut(iBase To UBound(v) - LBound(v) + iBase)
For i = LBound(v, 1) To UBound(v, 1)
Select Case VarType(v(i))
Case vbInteger, vbLong, vbSingle, vbDouble, vbCurrency, vbDate, vbByte
adOut(nOut + iBase) = CDbl(v(i))
Case Else
Err.Raise CVErr(xlErrValue)
End Select
nOut = nOut + 1
Next i
Make1D = adOut
End If
Else
ReDim adOut(iBase To iBase)
Select Case VarType(v)
Case vbInteger, vbLong, vbSingle, vbDouble, vbCurrency, vbDate, vbByte
adOut(iBase) = CDbl(v)
Case Else
Err.Raise CVErr(xlErrValue)
End Select
End If
End Function