jmaz
jmaz

Reputation: 527

Need faster loop

The objective is to copy and past n-1 cells for large n in the fastest time

This loop works, but runtime is long for large n:

For i = 1 to n
Range("A" & i).Copy Destination:=Range("A" & i + 1)
Next

I would think this loop would be faster, but it does not work:

For i = 1 to n
Range("A" & i + 1) = Range("A" & i)
Next

(The above does work if .value is added, but the format must be copied as well.)

What is the fastest approach?

Upvotes: 0

Views: 56

Answers (1)

tigeravatar
tigeravatar

Reputation: 26640

Do you need a loop at all? It looks like this is what you're trying to do:

Range("A1").Copy Range("A2:A" & n + 1)

Upvotes: 1

Related Questions