Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

ADO and EXCEL

Status
Not open for further replies.

mathon

Programmer
Apr 20, 2005
31
0
0
DE
Hi,

I want to understand the code of the following example
I have a worksheet with the follwing table starting at A1:
Monat Wert
Januar 1
Februar 2
März 3
Januar 4
Februar 5
März 6
Januar 7
Februar 8
März 9
Januar 10
Februar 11
März 12
Dezember 13

Unfortunately I do not understand the following method:

Code:
Private Function AusgabePerGetRows(DasRecordSet As Object, StartAusgabe As Range) As Long
' Peter Haserodt 2007
Dim vX As Variant, iRowCount As Long, iColCount As Long
On Error GoTo Fehler
StartAusgabe.CurrentRegion.Clear
vX = WorksheetFunction.Transpose(DasRecordSet.getrows)
iRowCount = UBound(vX, 1)
On Error Resume Next
iColCount = UBound(vX, 2)
On Error GoTo Fehler
If iColCount = 0 Then
	With StartAusgabe.Parent
		.Range(.Cells(StartAusgabe.Row, StartAusgabe.Column), _
			.Cells(StartAusgabe.Row, StartAusgabe.Column + iRowCount - 1)).Value = vX
	End With
	AusgabePerGetRows = 1
Else
	With StartAusgabe.Parent
		.Range(.Cells(StartAusgabe.Row, StartAusgabe.Column), _
			.Cells(StartAusgabe.Row + iRowCount - 1, StartAusgabe.Column + iColCount - 1)).Value = vX
	End With
	AusgabePerGetRows = iRowCount + 1
End If
Exit Function
Fehler:
AusgabePerGetRows = 0
End Function

When I use this example with March - März -> I have the following statements:
Code:
vX = WorksheetFunction.Transpose((2,4)) //The Recordset which I gave over to the function has 2 columns and 4 rows
vx(4,2) //with the Transpose function I transpose the array in an array with 4 rows and 2 columns
iRowCount = 4
iColCount = 2
Range(Cells(2,2),Cells(5,3)).Value = vX
AusgabePerGetRows = 5
-> Was the interpretation right?
-> Why does the author use iRowCound + 1 as return value, there are only 4 recordsets..?:((

If I go through the code with query string changed to december the statements would look as follows:
Code:
vX = WorksheetFunction.Transpose((2,1)) //the recordset consits of 2 columsn and 1 row
vX(1,2) //the transposed array
iRowCount = 1
iColCount = 2
-> But now he goes to the "If iColCoun=0 Then" branch although iColCount is 2 and not 0 in my point of view?

has anybody an idea how this code works? :((

regards
matti
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top