I have this code below with a loop, outputting 117 records into excel. I want to output 12 records then skip a line, another 12 then skip a line to the finish of all the data onto the same excel sheet. please help.
Code:
MySQL = "SELECT convert(datetime, RunMonth + '01', 112) as EffectiveMonth, SalaryBill, Rate " _
& "From Hpacc4 " _
& "where Scheme = '" & frmLogin.MaskEdBox1.Text & "' " _
& "AND convert(datetime, RunMonth + '01', 112) <= '" + RunMonthDate + "01 ' " _
& "AND convert(datetime, RunMonth + '01', 112) > DATEADD(yyyy,-5, convert(datetime, '20130201', 112)) " _
& "AND AccCode = '110' order by EffectiveMonth "
With rsHPData
.CursorLocation = adUseClient
.LockType = adLockReadOnly
.Open MySQL, cnHPtest, adOpenForwardOnly, adLockReadOnly
End With
numRecs = rsHPData.RecordCount
With oWS
'SET THE TOP ROWS WITH TITLES--Change Font to Bold
.Range("A2:C3").Font.Bold = True 'sets top row (stuff below) in bold print
.Cells(2, 1).Value = "Month"
.Cells(2, 2).Value = "Payroll"
.Cells(2, 3).Value = "Rate"
'Run through the RECORDSET, stating in ROW 2, until end of the RECORDSET
For x = 3 To numRecs + 1
.Cells(x, 1).Value = Format(rsHPData!EffectiveMonth, "mmmm-yyyy")
.Cells(x, 2).Value = Trim(rsHPData!SalaryBill)
.Cells(x, 3).Value = Trim(rsHPData!Rate)
rsHPData.MoveNext 'Move through the RECORDSET
'For
' I think twelve intervals has to come here
'Next
Next x
End With
'This for-loop makes the columns just wide enough for the largest 'string' in each column
For x = 1 To 3 'where 3, in my case is three columns (State Name, State Abbreviation and Date Entered Union
oWS.Columns(x).AutoFit
Next x
'close down the rs and connection
rsHPData.Close
cnHPtest.Close
oExcel.Visible = True 'so you can see what you did
'set up the active excel sheet
Set oWS = oExcel.ActiveSheet
Set oWB = oExcel.ActiveWorkbook
oWB.SaveAs FileName:=App.Path + "\Recon.xlsx" 'use whatever name you want here
Screen.MousePointer = vbDefault