A better way to write to a range:Filling a range : Cell « Excel « VBA / Excel / Access / Word






A better way to write to a range:Filling 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

 








Related examples in the same category

1.Is a cell empty
2.Get the last cell
3.Magic Squares
4.Nest If statement in Do Loop While with comparison operators
5.Nest If statement in Do Loop Until for cells
6.Is active cell empty
7.Transposing is taking a rectangular block of data and rotating it so that columns become rows and vice versa.
8.Uses nested For/Next loops to count the total number of cells used in all open worksheets:
9.Selects cell G4
10.Use arrays to fill ranges faster
11.Moving the pointer to the cell containing the greatest value