The code below illustrates that you can set the value of a range of cells to values contained in a same-sized array with one VBA statement and it is fast:
Range("A1:B10000") = aKey
But, the same cannot be used to set the Font Size property. The following statement gives an error:
Range("A1:B10000").Font.Size = aKey
Setting the Font Size cell by cell in a loop takes 71 times longer than the single statement above to set the cell value.
Is there anything analogous to the statement Range("A1:B10000") = aKey to set Font Size (or other cell format properties)?
Thanks.
Code
Range("A1:B10000") = aKey
But, the same cannot be used to set the Font Size property. The following statement gives an error:
Range("A1:B10000").Font.Size = aKey
Setting the Font Size cell by cell in a loop takes 71 times longer than the single statement above to set the cell value.
Is there anything analogous to the statement Range("A1:B10000") = aKey to set Font Size (or other cell format properties)?
Thanks.
Code
VBA Code:
Sub qwerty()
Dim aKey(1 To 10000, 1 To 2) As Variant
For i = 1 To 10000
aKey(i, 1) = Math.Round(Rnd * 10) + 8
aKey(i, 2) = Math.Round(Rnd * 10) + 8
Next i
Debug.Print 1, [now()]
Range("A1:B10000") = aKey
Debug.Print 2, [now()]
'DOES NOT WORK - Error "unable to set the Font property"
'Range("A1:B10000").Font.Size = aKey
'Takes 71 times longer than above.
For i = 1 To 10000
Range("A1").Offset(i - 1, 0).Font.Size = aKey(i, 1)
Range("A1").Offset(i - 1, 1).Font.Size = aKey(i, 2)
Next i
Debug.Print 3, [now()]
End Sub