Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/vba/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在VBA中动态选择行_Vba_Excel - Fatal编程技术网

在VBA中动态选择行

在VBA中动态选择行,vba,excel,Vba,Excel,我想在VBA中动态选择标准偏差计算的行数 目前我有以下代码: Sub Stdev() Dim x as integer x=10 Range("E1").Select ActiveCell.FormulaR1C1 = "=STDEV(R[1]C:R[5]C)" Range("E1").Select ActiveCell.FormulaR1C1 = "=STDEV(R[1]C:R[x]C)"'this is my attempt at dynamic calcul

我想在VBA中动态选择标准偏差计算的行数

目前我有以下代码:

Sub Stdev()

Dim x as integer
x=10
    Range("E1").Select
    ActiveCell.FormulaR1C1 = "=STDEV(R[1]C:R[5]C)"
    Range("E1").Select
    ActiveCell.FormulaR1C1 = "=STDEV(R[1]C:R[x]C)"'this is my attempt at dynamic calculation
End Sub
如何更正它以选择x中指定的行数?

请尝试:

Range("E1").FormulaR1C1 = "=STDEV(R[1]C:R[" & x & "]C)" 范围(“E1”)。公式1c1=“=STDEV(R[1]C:R[”&x&“]C)”
如果我想让它成为一个函数而不是一个子函数,我该怎么做?你想要什么作为函数的输入和输出?作为输入,我想要灵活地选择随机范围的行(比如1到30或4到19等,所以我将开始和结束行数作为参数传递给函数),我想得到标准偏差,作为指定单元格范围的输出。