0

I have an array of SQL statements which i loop through, execute, obtain the results and paste.

Most of the statements return just the one value but one of the SQL functions returns four values. I would like to hold an array of ranges which I can just paste the results of each SQL function into.

What would be the correct code from the point I return the recordset, to the point which I paste the recordset data, which would work for 1 value results and 4 value results? Should I be using Something = rs.getrows?? and what paste statement should I use?

The four value-result will be pasted into a vertical range of four cells, named X.

EDIT, got this so far:

For i = LBound(SQLFunctionArray, 1) To UBound(SQLFunctionArray, 1)

    If UseCurrencyAsArg(i) = True Then
        SecondArg = Ccy
    Else
        SecondArg = FileName
    End If

    SQLFunctionToCall = SQLFunctionArray(i)
    Range(RangeForPasting(i)) = WorksheetFunction.Transpose(GetSQLData(COB, SecondArg, SQLFunctionToCall))

Next

but it doesnt work for the four-value SQL result. GetSQLData returns the rs.getrows array

4

1 回答 1

0

您可以使用此函数翻转 GetRows 数组:

Function TransposeGetRows(arr)
    Dim nr As Long, nc As Long
    Dim r As Long, c As Long
    Dim arrOut()
    nr = UBound(arr, 2)
    nc = UBound(arr, 1)
    ReDim arrOut(0 To nr, 0 To nc)
    For r = 0 To nr
        For c = 0 To nc
            arrOut(r, c) = arr(c, r)
        Next c
    Next r
    TransposeGetRows = arrOut
End Function

然后像这样将数组放在工作表上:

Range(RangeForPasting(i)).Resize(UBound(arr, 1) + 1, _
                                 UBound(arr, 2) + 1).Value = arr
于 2012-05-29T16:54:04.500 回答