title: Paste results of SQL query into specifc cells based on value of other cells
body: <p>So in my main sheet of the workbook I have a column containing times, 9:00AM etc. and I use the following code to paste values copied from another workbook into different cells based on what time of day it is:</p>
  
  
  
  <pre class="lang-vb prettyprint-override"><code>lPasteRow = Application.Match(CDbl(Time()), sht_Target.Range("A:A"), 1)
  sht_Target.Cells(lPasteRow, 3) = rng_data.Value
  </code></pre>
  
  <p>This works perfectly fine. But only part of my data is pulled from another worksheet. The other half comes from SQL queries. The queries themselves run perfectly and they paste right now into just a single cell for testing purposes. I now need to get them paste into specific cells based on the time of day just like the above code. If the following is my SQL query sub:</p>
  
  <pre class="lang-vb prettyprint-override"><code> Dim Sheet1 As Worksheet
  Dim lastRow As Long
  lastRow = ActiveSheet.UsedRange.Rows.Count
  Set sht_Target = ThisWorkbook.Worksheets("Main Sheet")
  Dim path As String
  
  Dim Cn As ADODB.Connection
  Dim Server_Name As String
  Dim Database_Name As String
  Dim SQLStr As String
  Dim rs As ADODB.Recordset
  Set rs = New ADODB.Recordset
  
  
  
   Set Cn = New ADODB.Connection
   Cn.Open "Driver={SQL Server};Server=" &amp; Server_Name &amp; ";Database=" &amp;          Database_Name &amp; ""
  
  
   rs.Open SQLStr, Cn, adOpenStatic
  
   With sht_Target.Range("Q2")
      .ClearContents
      .CopyFromRecordset rs
   End With
  
   rs.Close
   Set rs = Nothing
   Cn.Close
   Set Cn = Nothing
  </code></pre>
  
  <p>how would I go about getting this to paste the results into the cells based on the time of day?</p>
  
  <p>Edit: I should probably clarify that all the SQL queries work perfectly and return just a number. Either a total or a percentage. I just need to make sure that if it is 10AM then then results go into Row 3, because A3 says 10:00 AM and so on. </p>