Quantcast
Channel: Active questions tagged excel - Stack Overflow
Viewing all articles
Browse latest Browse all 88868

Create a table in excel sheet and add rows in table with SQL in loop

$
0
0

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

Viewing all articles
Browse latest Browse all 88868


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>