VBA to perform multiple formula and display only final result
i have a code, and i dont want the intermediate value to be displayed in excel sheet. Below is the example, i just want the final cell AM12 and i dont want the intermediate results to be printed in excel. How can i do this in VBA, any way to do it.
Range("AG3").Select
ActiveCell.FormulaR1C1 = "=(RC[-28]/R[-1]C[-28])*100"
Range("AG3").Select
Selection.AutoFill Destination:=Range("AG3:AG7204")
Range("AG3:AG7204").Select
Range("AH3").Select
ActiveCell.FormulaR1C1 = "=RC[-1]-100"
Range("AH3").Select
Selection.AutoFill Destination:=Range("AH3:AH7204")
Range("AH3:AH7204").Select
Range("AI3").Select
ActiveCell.FormulaR1C1 = "=RC[-1]*(2/35)"
Range("AI4").Select
ActiveCell.FormulaR1C1 = "=((RC[-1]-R[-1]C)*(2/35))+R[-1]C"
Range("AI4").Select
Selection.AutoFill Destination:=Range("AI4:AI7204")
Range("AI4:AI7204").Select
Range("AJ3").Select
ActiveCell.FormulaR1C1 = "=RC[-1]*10"
Range("AJ3").Select
Selection.AutoFill Destination:=Range("AJ3:AJ7204")
Range("AJ3:AJ7204").Select
Range("AK3").Select
ActiveCell.FormulaR1C1 = "=RC[-1]*(2/20)"
Range("AK4").Select
ActiveCell.FormulaR1C1 = "=((RC[-1]-R[-1]C)*(2/20))+R[-1]C"
Range("AK4").Select
Selection.AutoFill Destination:=Range("AK4:AK7204")
Range("AK4:AK7204").Select
Range("AL12").Select
ActiveCell.FormulaR1C1 = "=AVERAGE(R[-9]C[-1]:RC[-1])"
Range("AL12").Select
Selection.AutoFill Destination:=Range("AL12:AL7204")
Range("AL12:AL7204").Select
Range("AL13").Select
ActiveCell.FormulaR1C1 = "=((RC[-1]-R[-1]C)*(2/11))+R[-1]C"
Range("AL13").Select
Selection.AutoFill Destination:=Range("AL13:AL7204")
Range("AL13:AL7204").Select
Range("AM12").Select
ActiveCell.FormulaR1C1 = "=RC[-2]-RC[-1]"
Range("AM12").Select
Selection.AutoFill Destination:=Range("AM12:AM7204")
Range("AM12:AM7204").Select
The best way forward from what you have already recorded as a macro would be to add code at the end to delete the columns that hold intermediate values.
For example, looks like in your case AH to AL are columns with intermediate values.
So you can add this to the end of your macro code.
sourceSheet.Columns("AH:AL").EntireColumn.Delete
This way, excel will do the necessary computation and then delete the intermediate value columns.