' Loop through the a table and copy them to worksheet.
uRow = 4
Do Until rs.EOF
For i = 0 To rs.Fields.Count - 1
'here is the reference to the worksheet
Sht.Cells(uRow, i + 1).Value = rs(i)
Next i
rs.MoveNext
uRow = uRow + 1
Loop
' Another example of loop and copy
uRow2 = 2
h = 3
Do Until rs2.EOF
Sht.Cells(uRow2, h).Value = rs2(i2)
rs2.MoveNext
h = h + 3
Loop
With Sht
.Rows("2").NumberFormat = "hh:mm"
End With
' Example of formatting the excelsheet
With Sht
.Name = "Timetable"
.Rows("4:" & RecordQuantity).RowHeight = 36
.Rows(2).Font.Bold = True
.Columns(1).Font.Bold = True
.Cells.Interior.ColorIndex = "2"
Do Until b = RecordQuantity2 * 3 + 3 + 1
.Range(.Cells(2, c), .Cells(2, b)).Merge
b = b + 3
c = c + 3
Loop
Do Until d = RecordQuantity2 * 3 + 3
.Range(.Cells(1, d), .Cells(RecordQuantity, d)).Interior.ColorIndex = "6"
d = d + 3
Loop
.Columns("A").Autofit
.Rows("2").HorizontalAlignment = 3
.Rows("2").VerticalAlignment = 2
.Rows("4:" & RecordQuantity).VerticalAlignment = 2
Do Until a = RecordQuantity2 * 3 + 3
.Columns(a).ColumnWidth = 0.4
.Columns(a - 1).ColumnWidth = 2.5
.Columns(a + 1).ColumnWidth = 2.5
a = a + 3
Loop
Sht.PageSetup.Orientation = 2 'xlLandscape
End With