找回密码
 立即加入
搜索
进吧 门户 技巧分享 查看内容

EXCEL 数组自动排列所有结果-自定义函数实现ETmatrix效果

2023-12-26 09:09| 发布者: admin| 查看: 15| 评论: 0

摘要: Function PermutationCombination(data1 As Range, data2 As Range, data3 As Range) As Variant ' data1,data2,data3 分别为三组数据的单元格范围,如 A1:A5 ' 返回三组数据的所有排列组合 Dim output() As V ...
Function PermutationCombination(data1 As Range, data2 As Range, data3 As Range) As Variant
    ' data1,data2,data3 分别为三组数据的单元格范围,如 A1:A5
    ' 返回三组数据的所有排列组合
    
    Dim output() As Variant
    ReDim output(1 To data1.Cells.Count * data2.Cells.Count * data3.Cells.Count, 1 To 3)
    
    Dim i As Long, j As Long, k As Long
    Dim idx As Long
    
    For i = 1 To data1.Cells.Count
        For j = 1 To data2.Cells.Count
            For k = 1 To data3.Cells.Count
                idx = idx + 1
                output(idx, 1) = data1.Cells(i, 1).Value
                output(idx, 2) = data2.Cells(j, 1).Value
                output(idx, 3) = data3.Cells(k, 1).Value
            Next k
        Next j
    Next i
    
    PermutationCombination = output
End Function
1

鲜花

握手

雷人

路过

鸡蛋

刚表态过的朋友 (1 人)

手机版|进吧

GMT+8, 2024-5-19 23:24 , Processed in 0.031200 second(s), 17 queries .

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

返回顶部