|
- Option Explicit
- ' 使用字典对象比多重循环更高效
- Sub Demo()
- Dim objDic As Object, rngData As Range
- Dim i As Long, iR As Long, sKey
- Dim arrData, arrRes
- Set objDic = CreateObject("scripting.dictionary")
- Set rngData = Range("U7:X" & Cells(Rows.Count, "U").End(xlUp).Row)
- arrData = rngData.Value
- ReDim arrRes(1 To UBound(arrData) * 2, 0)
- For i = LBound(arrData) To UBound(arrData)
- If arrData(i, 1) = "T" Then
- sKey = arrData(i, 4) & "," & arrData(i, 3)
- If Not objDic.exists(sKey) Then
- iR = objDic.Count + 1
- objDic(sKey) = iR
- End If
- End If
- Next i
- iR = 0
- For Each sKey In objDic.keys
- iR = iR + 1
- arrRes(iR, 0) = "T(PROFP_" & objDic(sKey) & ")=TOL/PROFP," & sKey
- Next
- For i = LBound(arrData) To UBound(arrData) - 4
- If arrData(i, 1) = "DIM" And arrData(i + 4, 1) = "T" Then
- iR = iR + 1
- arrRes(iR, 0) = "OUTPUT/FA(" & arrData(i, 2) & ")"
- sKey = arrData(i + 4, 4) & "," & arrData(i + 4, 3)
- If objDic.exists(sKey) Then
- iR = iR + 1
- arrRes(iR, 0) = arrRes(iR - 1, 0) & ",TA(PROFP_" & objDic(sKey) & ")"
- End If
- End If
- Next i
- Range("AJ2").Resize(iR, 1) = arrRes
- End Sub
复制代码 |
评分
-
1
查看全部评分
-
|