I have an Excel sheet containing table like data
strSQL = "SELECT S.FIELD_NAME1,S.FIELD_NAME2,S.FIELD_NAME3 from [SourceData$A1:IV6] S"
Dim cn as ADODB.Connection
Dim rs as ADODB.Recordset
cn.Open strCon
Set rs = CmdSqlData.Execute()
Worksheets("SourceData").Cells.ClearContent
Worksheets("AnswerData").Cells(2, 1).CopyFromRecordset rs
Results :
Only first row and other records are ignored.
I have tried below query .,
strSQL = "SELECT COUNT(*) from [SourceData$A1:IV6] S"
Which gives 5 as result.
Please let me know why other records not copied into recordset?
Here’s a subroutine that successfully pastes a recordset.
Note that the range it pastes to is the same size of the recordset via the intMaxRow and intMaxCol variables:
Using that example as a model, I’d try somehting like this for your code: