VBA Excel中的嵌套循环

蒙亨

我需要根据此数据创建一个列表。我需要它通过数字080808来呈现数字000000。希望像这样格式化数据...

000000-CHW设备RTU

000001-CHWER EQUIPMENT CHICKEN

等等,我需要列出所有可能的数字组合,并附上可能的描述。喜欢:

= concatenate(A1,C1,E1,“-”,B1,“”,D1,“”,F1)

除了遍历所有可能的组合。有人可以帮助我提出一个可以做到这一点的循环吗?我对Macros不太熟悉。

A   B               C   D               E   F
00  CHW             00  Equipment       00  RTU
01  HHW             01  SM Steel Pipe   01  Chiller
02  Steam           02  LB Steel Pipe   02  Split System
03  Med Gas         03  Copper          03  Pump
04  UG/Soil         04  Cast Iron       04  Boiler
05  Domestic Water  05  Plastic         05  Cooling Tower
06  Compressed Air  06  Double-Wall     06  Air Compressor
07  Natural Gas     07  Sheetmetal      07  Fan
08  Refrigerant     08  Fixtures        08  Unit Vent
用户名
    Sub GetAllCombinations()

    Dim rowNum As Integer
    Dim rowValue As String
    Dim celRange As String

    Dim A As String
    Dim B As String
    Dim C As String
    Dim D As String
    Dim E As String
    Dim F As String


    rowNum = 1

        For Each cell In Range("A2:A10")

            A = Range("A" + CStr(cell.Row)).Value
            B = Range("B" + CStr(cell.Row)).Value

            For Each cell2 In Range("C2:C10")

                C = Range("C" + CStr(cell2.Row)).Value
                D = Range("D" + CStr(cell2.Row)).Value

                For Each cell3 In Range("E2:E10")

                    E = Range("E" + CStr(cell3.Row)).Value
                    F = Range("F" + CStr(cell3.Row)).Value

                    Range("H" + CStr(rowNum)).Value = A + C + E + " - " + B + D + F

                    rowNum = rowNum + 1
                Next

            Next

        Next

    End Sub

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章