我有一张工作表,我的x数据集保持不变,我想使用不同的y数据集运行100个不同的回归。
我的代码是
Application.Run "ATPVBAEN.XLAM!Regress", ActiveSheet.Range("$F$3:$F$22"), _
ActiveSheet.Range("$C$3:$E$22"), False, False, , Range("F2").Value, False, False, _
False, False, , False
如何循环这个以便y数据集将更改为下一列,在本例中为G3:G22并且还根据标题是什么标题来命名工作表它是单元格G2?
谢谢
答案 0 :(得分:2)
也许你正在寻找这样的东西:
Dim x as WorkSheet : Set x = ActiveSheet '<-- I'd recommend to set it with the sheet's name (i.e. x = Worksheets("Xdataset"))
Dim col as string
For Each col In Array("F", "G") '<-- setup the columns you want to iterate on
Application.Run "ATPVBAEN.XLAM!Regress", x.Range(col & "3:" & col & "22"), _
x.Range("$C$3:$E$22"), False, False, , x.Range(col & "2").Value, False, False, _
False, False, , False
Next
修改
由于您需要到CU
,因此阵列解决方案可能难以输入。对于这种情况,更好的解决方案是:
Dim x as WorkSheet : Set x = ActiveSheet '<-- I'd recommend to set it with the sheet's name (i.e. x = Worksheets("Xdataset"))
Dim col as Range
For Each col in x.Range("F3:CU22").Columns
Application.Run "ATPVBAEN.XLAM!Regress", col,
x.Range("$C$3:$E$22"), False, False, , col.Cells(0).Value, False, False, False, False, , False
Next