In excel vba ,I am running SQL in a for loop and I want the result of SQL in loop to be added as a table in my excel worksheet. the example code snippet is given below. So the below code just checks user activity between 2 dates. I need this data to be presented in form of table with excel vba.
Sub activity_count
Dim x as date
Dim start_date as date
Dim End_date as date
Dim rsResult as object
Dim strSql as string
for x=start_date to end_date
Set rsResult =CreateObject("ADODB.Recordset")
strSQL="select logdate, username, activity_count from table where logdate='"&start_date
strSQL= strSQL & "'"
strSQL=strSQL & ";"
Call Logon
rsResult.Open strSQL, Conn
'with your help ,I need the code to write this data in same excel sheet in the form of table.
rsResult.close
Set rsResult=nothing
Set Conn=nothing
strSQL=""
start_date=DateAdd("d",1,start_date)
next
end sub