Hello,
I am new to excel help and VBA in general. Hopefully someone can help my situation. I have been assigned the task of taking data from a SQL database and formatting it into a spreadsheet already in existance. I have already written the sql part, however I am having an issue with putting that data into certain columns and rows depending on which week and day it is. This seems like a simple operation, but I am new to VBA and having a hard time figure this out.
So far I have,
Public Sub ConnectionStringX()
Dim C1 As ADODB.Connection
Dim Week1_Monday_A As ADODB.Recordset
Set Week1_Monday_A = New ADODB.Recordset
Set C1 = New ADODB.Connection
C1.ConnectionString = "driver={Adaptive Server Anywhere 9.0};" & _
"server=sqlserver;uid=uid;pwd=pwd;database=database.db"
C1.ConnectionTimeout = 30
C1.Open
With Week1_Monday_A
.ActiveConnection = C1
.Open "select A,B,C,D,E,F,G,H,I,J,K from database.mytable where business_date = today() and dayname(business_date)='Monday'"
ThisWorkbook.Sheets("week1").Range("H25,E7,B18,E9,H5,H3,F8,D23,G7,H9,B4").CopyFromRecordset Week1_Monday_A
.Close
End With
End Sub
Bookmarks