I am attaching the code here. I am very new to VBA and trying to do a complex calculation using Macro. Please help me improve the speed of the attached code. The code works fine and produces the end output. The program is intended to do the following. I am calling the below two subs after data is filled in the sheet. Copy and paste two sets of variable in two specified cell Excel does a complex calculation using FILTER command & other INDEX and MATCH Formulas Copy and paste the output to a location This is required to done 1500 times for two sets of data. Present execution time is 10 minutes.
Sub CF_Amb_Pr_NG()
Dim intX As Integer
Dim copyRng As String
X = 43
For X = 40 To 1539
Sheets("CC_NG_APr").Select
Range("C2").Select
Application.CutCopyMode = False
ActiveCell.FormulaR1C1 = "=R" & X & "C2"
Range("C3").Select
Application.CutCopyMode = False
ActiveCell.FormulaR1C1 = "=R" & X & "C3"
Range("E2").Select
Selection.Copy
Let copyRng = "D" & X
Range(copyRng).Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Next X
End Sub
Sub CF_RH_NG()
Dim intX As Integer
Dim copyRng As String
X = 33
For X = 32 To 1531
Sheets("CC_NG_RH").Select
Range("C2").Select
Application.CutCopyMode = False
ActiveCell.FormulaR1C1 = "=R" & X & "C2"
Range("C3").Select
Application.CutCopyMode = False
ActiveCell.FormulaR1C1 = "=R" & X & "C3"
Range("E2").Select
Selection.Copy
Let copyRng = "D" & X
Range(copyRng).Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Next X
End Sub
Attached screenshot of sheet in formula mode to explain what exactly is going on in E2
based on the values fed in C2
& C3
. Basis the value entered in C2
& C3
, formula to be chosen to calculate E2
is chosen and final value is shown. I need to get value in E2
for 3000 sets of data in C2
& C3
Thanks a lot for helping !