I am trying to create a macro in excel which does a bunch of basic calculations (multiplication, division, etc.) using columns from a table in Excel. My table looks like this:
The problem I have is that, as part of the calculations, the user needs to specify a constant "a" that will be used to obtain the values of a column named "Z2"with this expression: values in "Z2" = Values in column "X1"+ Values in column "Y2" multiplied by constant 'a'. In order to achieve this I tried with the following code:
Sub Macro_test()
Dim constant As Double
constant = InputBox("Insert constant 'a'")
Range("D1").Select
ActiveCell.FormulaR1C1 = "X1"
Range("D2").Select
ActiveCell.FormulaR1C1 = "=[@X]*SIN[@Y]"
Range("E1").Select
ActiveCell.FormulaR1C1 = "Y2"
Range("E2").Select
ActiveCell.FormulaR1C1 = "=[@X]*[@Y]*[@X1]"
Range("F1").Select
ActiveCell.FormulaR1C1 = "Z2"
Range("F2").Select
ActiveCell.FormulaR1C1 = "=[@X1]+[@Y2]*constant"
Everything works well but the operation that involves the constant does not work. Any idea on what am I doing wrong?. Thanks in advance for the help.