I'm trying to get records from a database and fill them into excel.
This is how I get the data and fill it (note: the query is simplified, I can't just ORDER BY DESC
):
Sub FillPersons(ByRef connection As ADODB.connection)
Dim recordSet As ADODB.recordSet
Set recordSet = New ADODB.recordSet
Dim sql As String
sql = "SELECT TOP 2 Id FROM Persons"
recordSet.activeconnection = connection
recordSet.Open sql
Dim a As Variant
If Not recordSet.EOF Then
a = recordSet.GetRows
a.Reverse (a)
Sheet1.Cells(10, 2).Resize(UBound(a, 1) + 1, UBound(a, 2) + 1).Value = a
End If
'Sheet1.Range("B10").CopyFromRecordset recordSet
recordSet.Close
connection .Close
Set connection = Nothing
End Sub
Unfortunately, the result looks like this:
B10B11
2 1
instead of
B10B11
1 2
I've tried to reverse a
but unfortunately I can't get it to work.
Is there a trick to get the correct result?
Thanks in advance