I've written the function below that I would like to use dynamically in my excel sheet where the function would assess the value of the variable selected in the formula and based on that value, perform a simple calculation referencing values in cells in different columns but in the same row.
I know that the code below works, but how can I rewrite the ranges so that my function can be used dynamically for each row of the same column?
Function AddedValue(TabSize As Integer)Select Case TabSize
Case 2 AddedValue = Range("K3") * (Range("N3") * (Range("H3") * 0.001)) Case 4 AddedValue = Range("K3") * (Range("O3") * (Range("H3") * 0.001)) Case 6 AddedValue = Range("K3") * (Range("P3") * (Range("H3") * 0.001)) Case 8 AddedValue = Range("K3") * (Range("Q3") * (Range("H3") * 0.001)) Case 10 AddedValue = Range("K3") * (Range("R3") * (Range("H3") * 0.001))
End Select
End Function
#excel #excel-vba