我找到了编写3列数据的所有可能组合的脚本,但我试图修改代码写4列,可能5列,我不知道如何.如果有人可以提供帮助那就太棒了!我已经尝试过做我认为应该工作的东西,在他们会遵循的地方添加额外的变量(我认为他们会在逻辑上去)但是我正在解决"编译错误:没有循环".
以下是User Excellll的3列(未经我修改)的代码.
代码的描述如下:"此代码将从A,B和C列获取数据,并提供您在E,F和G列中描述的输出."
Sub combinations()
Dim c1() As Variant
Dim c2() As Variant
Dim c3() As Variant
Dim out() As Variant
Dim j, k, l, m As Long
Dim col1 As Range
Dim col2 As Range
Dim col3 As Range
Dim out1 As Range
Set col1 = Range("A1", Range("A1").End(xlDown))
Set col2 = Range("B1", Range("B1").End(xlDown))
Set col3 = Range("C1", Range("C1").End(xlDown))
c1 = col1
c2 = col2
c3 = col3
Set out1 = Range("E2", Range("G2").Offset(UBound(c1) * UBound(c2) * UBound(c3)))
out = …Run Code Online (Sandbox Code Playgroud) 我试图在vba中移动平均值编码,但以下各处返回相同的值.
Function trial1(a As Integer) As Variant
Application.Volatile
Dim rng As Range
Set rng = Range(Cells(ActiveCell.Row, 2), Cells(ActiveCell.Row - a + 1, 2))
trial1 = (Application.Sum(rng)) * (1 / a)
End Function
Run Code Online (Sandbox Code Playgroud)