Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/excel/27.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
Excel:创建A列的所有可能组合,并(单独)创建不限数量的B列到“1”;x";_Excel_Combinations - Fatal编程技术网

Excel:创建A列的所有可能组合,并(单独)创建不限数量的B列到“1”;x";

Excel:创建A列的所有可能组合,并(单独)创建不限数量的B列到“1”;x";,excel,combinations,Excel,Combinations,我在A列中有数据,需要所有组合的结果以及B、C、D等列中的每个数据 所以我不需要所有列的组合,我需要AB,AC,AD,AE,等等 对于我来说,更容易将每个单元格的结果与现在合并的数据之间的空间合并 比如说 Blue One Red Two Yellow Three 将成为 Blue One Blue Two etc 希望能够指定组合的顺序,例如,B、C、D等列的所有可能性。。。如果列A单元格数据被追加,而不是继续这将尽可能多地使用数组,从而限制工作表的访问时间 Sub mygrou

我在A列中有数据,需要所有组合的结果以及B、C、D等列中的每个数据

所以我不需要所有列的组合,我需要AB,AC,AD,AE,等等

对于我来说,更容易将每个单元格的结果与现在合并的数据之间的空间合并

比如说

Blue   One
Red    Two
Yellow Three
将成为

Blue One
Blue Two
etc

希望能够指定组合的顺序,例如,B、C、D等列的所有可能性。。。如果列A单元格数据被追加,而不是继续

这将尽可能多地使用数组,从而限制工作表的访问时间

Sub mygrouping()
    With Worksheets("Sheet6") ' change to your sheet
        Dim rngA As Variant
        rngA = .Range("A1", .Cells(.Rows.Count, 1).End(xlUp)).Value

        Dim rngOthers As Variant
        ReDim rngOthers(1 To Application.CountA(.Range("B1", .Cells(1040000, .Cells(1, .Columns.Count).End(xlToLeft).Column)))) As Variant
        Dim j As Long, k As Long, i As Long
        k = 1
        For j = 2 To .Cells(1, .Columns.Count).End(xlToLeft).Column
            rngintm = .Range(.Cells(1, j), .Cells(.Rows.Count, j).End(xlUp)).Value
            For i = 1 To UBound(rngintm, 1)
                If rngintm(i, 1) <> "" Then
                    rngOthers(k) = rngintm(i, 1)
                    k = k + 1
                End If
            Next i
        Next j
        Dim outarr() As Variant
        ReDim outarr(1 To UBound(rngA, 1) * UBound(rngOthers), 1 To 1)
        k = 1
        For i = 1 To UBound(rngA, 1)
            For j = 1 To UBound(rngOthers)
                outarr(k, 1) = rngA(i, 1) & rngOthers(j)
                k = k + 1
            Next j
        Next i


        'Outputs to another sheet change to your sheet name and desired location
        Worksheets("Sheet7").Range("A1").Resize(UBound(outarr, 1), 1).Value = outarr

    End With
End Sub
Sub-mygrouping()
将工作表(“表6”)更改为工作表
Dim rngA作为变体
rngA=.Range(“A1”,.Cells(.Rows.Count,1).End(xlUp)).Value
Dim rngOthers作为变体
ReDim rngOthers(1到Application.CountA(.Range(“B1”),.Cells(1040000,.Cells(1,.Columns.Count).End(xlToLeft.Column)))作为变量
长j,长k,长i
k=1
对于j=2到.Cells(1,.Columns.Count).End(xlToLeft).Column
rngintm=.Range(.Cells(1,j),.Cells(.Rows.Count,j).End(xlUp)).Value
对于i=1至UBound(rngintm,1)
如果rngintm(i,1)“,则
rngOthers(k)=rngintm(i,1)
k=k+1
如果结束
接下来我
下一个j
Dim outarr()作为变量
无线电发射(1对UBound(rngA,1)*UBound(rngOthers,1对1)
k=1
对于i=1至UBound(rngA,1)
对于j=1至UBound(Rngother)
输出(k,1)=rngA(i,1)和rngOthers(j)
k=k+1
下一个j
接下来我
'输出到另一张图纸将更改图纸名称和所需位置
工作表(“Sheet7”)。范围(“A1”)。调整大小(UBound(outarr,1),1)。值=outarr
以
端接头

这将需要vba。公式不包含开放式列计数。