Hello All,
I am wanting to know if is at all possible to create a recordset via SQL statement and then select the data from 1 of the columns in that recordset which in turn will be paste on an excel sheet.
Code I Have so far below:
Sub getscorecard(thing2 As String, thing3 As String, thing4 As String)
Dim rsSource As New ADODB.Recordset, sqlst As String
Application.ScreenUpdating = False
Sheets("imported scorecard").Visible = True
Sheets("imported scorecard").unprotect Password:="ateam"
MakeConn
sqlst = "SELECT STATEMENT" 'Is rather long so didn't want to post!
With rsSource
.ActiveConnection = conSC
.Open sqlst
Sheets("imported scorecard").Select
Cells.ClearContents
Set ws = Application.ActiveSheet
For iCols = 0 To rsSource.Fields.Count - 1
ws.Cells(1, iCols + 1).Value = rsSource.Fields(iCols).Name
Next
ws.Range(ws.Cells(1, 1), ws.Cell(1,rsSource.Fields.Count+1))
.Font.Bold = True
ws.Range("A2").CopyFromRecordset rsSource
End With
What I'm stuck on is how to actaully copy the column I want.
My guess was it would be straight forward and something like:
ws.Range("A2").CopyFromRecordset rsSource.Fields(6)
ws.Range("A2").CopyFromRecordset rsSource.Fields(6).value
But neither work.
End result all I want to be pasted is one column data based on cell value matches and looping through.
If anyone haas any idea will be much appreicated.
Many Thanks
Bantler
I am wanting to know if is at all possible to create a recordset via SQL statement and then select the data from 1 of the columns in that recordset which in turn will be paste on an excel sheet.
Code I Have so far below:
Sub getscorecard(thing2 As String, thing3 As String, thing4 As String)
Dim rsSource As New ADODB.Recordset, sqlst As String
Application.ScreenUpdating = False
Sheets("imported scorecard").Visible = True
Sheets("imported scorecard").unprotect Password:="ateam"
MakeConn
sqlst = "SELECT STATEMENT" 'Is rather long so didn't want to post!
With rsSource
.ActiveConnection = conSC
.Open sqlst
Sheets("imported scorecard").Select
Cells.ClearContents
Set ws = Application.ActiveSheet
For iCols = 0 To rsSource.Fields.Count - 1
ws.Cells(1, iCols + 1).Value = rsSource.Fields(iCols).Name
Next
ws.Range(ws.Cells(1, 1), ws.Cell(1,rsSource.Fields.Count+1))
.Font.Bold = True
ws.Range("A2").CopyFromRecordset rsSource
End With
What I'm stuck on is how to actaully copy the column I want.
My guess was it would be straight forward and something like:
ws.Range("A2").CopyFromRecordset rsSource.Fields(6)
ws.Range("A2").CopyFromRecordset rsSource.Fields(6).value
But neither work.
End result all I want to be pasted is one column data based on cell value matches and looping through.
If anyone haas any idea will be much appreicated.
Many Thanks
Bantler