Results 1 to 2 of 2

Placing values from query to multiple cells

Threaded View

  1. #1
    Registered User
    Join Date
    07-23-2012
    Location
    Georgia
    MS-Off Ver
    Excel 2003
    Posts
    1

    Placing values from query to multiple cells

    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
    Last edited by Cutter; 07-23-2012 at 04:28 PM. Reason: Added code tags

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1