[Solved] VBA Excel Optimization for ForLoop [closed]


Create a source array for your fruits.

Dim fruits
fruits = Array("Apple", "Orange", ... , "Mango")

Then use a Loop to assign values to Range.
You’ll need additional variables for it.

Dim n As Long, fruit

With Selection: n = 0
    For Each fruit In fruits
        .Offset(n) = fruit: n = n + 1
    Next
    .Resize(n + 1).Font.Bold = True '~~> format in one go
End With

I don’t know if you’ll consider this optimized enough but HTH.
Btw, I did not consider the shift in Column when you’re assigning the fruit Rambutan.
I leave it to you. It may require another variable and IF statement.

3

solved VBA Excel Optimization for ForLoop [closed]