Reset lngCount to the number of records in the query:rst.MoveLast
rst.MoveFirst
lngCount = rst.RecordCountFor n = 1 To lngCountWrite data from the recordset to cells in the current row of the worksheet, using the columnoff-
setargument to move to the next cell:rng.Value = Nz(rst![ShipCountry])
Set rng = rng.Offset(columnoffset:=1)
rng.Value = Nz(rst![Category])
Set rng = rng.Offset(columnoffset:=1)
rng.Value = Nz(rst![Product])
Set rng = rng.Offset(columnoffset:=1)
rng.Value = Nz(rst![Customer])
Set rng = rng.Offset(columnoffset:=1)
rng.Value = Nz(rst![OrderID])
Set rng = rng.Offset(columnoffset:=1)
rng.Value = Nz(rst![UnitPrice])
Set rng = rng.Offset(columnoffset:=1)
rng.Value = Nz(rst![Quantity])
Set rng = rng.Offset(columnoffset:=1)
rng.Value = Nz(rst![Discount])
Set rng = rng.Offset(columnoffset:=1)
rng.Value = Nz(rst![TotalPrice])Go to the next row of the worksheet, using the rowoffsetargument:rst.MoveNext
Set rng = rngStart.Offset(rowoffset:=n)
Next nDetermine the number of data rows in the worksheet with the UsedRangeproperty:lngRows = wks.UsedRange.Rows.Count
Debug.Print “Number of data rows in worksheet: “ & lngRowsDefine the data range:strRange = “A4:I” & CStr(lngRows)
Set rngData = wks.Range(strRange)Apply hairline borders to the data range:With rngData
.Borders(xlDiagonalDown).LineStyle = xlNone
.Borders(xlDiagonalUp).LineStyle = xlNonePart I The Office Components and What They Do Best