在 VBA 中循环回归

Looping a regression in VBA

我有一个工作表,我的 x 数据集保持不变,我想 运行 100 个不同的回归,使用不同的 y data-sets。

我的密码是

 Application.Run "ATPVBAEN.XLAM!Regress", ActiveSheet.Range("$F:$F"), _
 ActiveSheet.Range("$C:$E"), False, False, , Range("F2").Value, False, False, _
 False, False, , False

我如何循环这个以便 y 数据集将更改到下一列,在本例中为 G3:G22 并根据本例中的 header 命名工作表单元格 G2?

谢谢

也许您正在寻找这样的东西:

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:$E"), 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:$E"), False, False, , col.Cells(0).Value, False, False, False, False, , False
Next