Question

I am new to VBA. I am presently working on a validation tool already built by my predecessor. The issue I want clarification on is selecting the cell range based on the result of a formula in another cell.

For example, I need to find the standard deviation of 800 number among the 1000 numbers of a column say Column B. I use the formula STDEV.S(), with the range of two cells in the bracket. However, the range of two cells is varying, as the user can select and change the range. The selection of the range by user is printed in a cell, say Upper Limit in C16 and lower Limit in C15. Consider C16 has 950 and C16 has 150 value in them, in that case, how do I insert the formula for stdev.s().? Thanks in advance for the help.

Was it helpful?

Solution

Assuming that your Data is in Column B and your bounds are in C15 and C16

Sub PasteAFormula()

Dim strFormulaToPaste As String

    strFormulaToPaste = "B" & Range("C15").Value & ":B" & Range("C16").Value

    strFormulaToPaste = "=STDEV.S(" & strFormulaToPaste & ")"

    MsgBox strFormulaToPaste

End Sub

You can then put the contents of strFormulaToPaste into a cell.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top