I have below Excel VBA code in many places. It need to optimize to improve running speed. I do appreciate your help.
Someone within a loop:
For x = A_OFFSET_MARKETVALUE To A_OFFSET_CURRENT
Cells(nLevel1Position, iColumn).Select
Selection.Copy
Cells(nLevel1Position, iColumn + x).Select
Selection.PasteSpecial Paste:=xlPasteFormulas, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
Next x
For example: the above code copy Cells(11,13).Formula "=SUM(M12:M13)"
to Cells(11,14).Formula
, After copy and xlPasteFormulas
Cells(11,14).Formula
becomes "=SUM(N12:N13)
does anybody know why? But the result is expected. So if I use below code to optimized it
Cells(nLevel1Position, iColumn + x).Formula = Cells(nLevel1Position, iColumn).Formula
The Cells(11,14).Formula
always is "=SUM(M12:M13)"
. I do not know why? How should I optimized it and also get Cells(11,14).Formula
value "=SUM(N12:N13)"
Someone is not in a loop:
Cells(nLevel1Position, iColumn).Select
Selection.Copy
Cells(nLevel1Position, iColumn + A_OFFSET_MARKETVALUE).Select
Selection.PasteSpecial Paste:=xlPasteFormulas, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
The whole code is below for reference. There are many places need to be optimized. Unfortunately, I am very new to VBA,and my boss required it to be done in a very short time. So anybody can help me will be greate appreciated. Many many thanks.