Mega Code Archive

 
Categories / VisualBasic Script / Excel
 

A better way to write to a range

Sub LoopFillRange()     Dim CurrRow As Long, CurrCol As Integer     Dim CurrVal As Long     CellsDown = 3     CellsAcross = 4     StartTime = timer     CurrVal = 1     Application.ScreenUpdating = False     For CurrRow = 1 To CellsDown         For CurrCol = 1 To CellsAcross             ActiveCell.Offset(CurrRow - 1, _             CurrCol - 1).value = CurrVal             CurrVal = CurrVal + 1         Next CurrCol     Next CurrRow '   Display elapsed time     Application.ScreenUpdating = True     MsgBox Format(timer - StartTime, "00.00") & " seconds" End Sub