|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
- Sub Demo()
- Dim objDic As Object, rngData As Range
- Dim i As Long, j As Long, sKey As String
- Dim arrData1, arrData2, aCol, aTmp, iCnt As Long
- Dim oSht1 As Worksheet, oSht2 As Worksheet
- aCol = Split("2 3 4 5 14 17")
- iCnt = UBound(aCol)
- ReDim aTmp(iCnt)
- Set oSht1 = Sheets("表一")
- Set oSht2 = Sheets("表二")
- Set objDic = CreateObject("scripting.dictionary")
- Set rngData = oSht1.Range("A1").CurrentRegion
- arrData1 = rngData.Value
- arrData2 = oSht2.Range("A1").CurrentRegion.Value
- For i = LBound(arrData2) + 1 To UBound(arrData2)
- sKey = arrData2(i, 16) ' Col P
- If Len(sKey) > 0 Then
- For j = 0 To iCnt
- aTmp(j) = arrData2(i, aCol(j))
- Next
- If objDic.exists(sKey) Then
- Dim b: b = objDic(sKey)
- If objDic(sKey)(4) < arrData2(i, 14) Then
- objDic(sKey) = aTmp
- End If
- Else
- objDic(sKey) = aTmp
- End If
- End If
- Next i
- For i = LBound(arrData1) + 1 To UBound(arrData1)
- sKey = arrData1(i, 4) ' Col D
- If Len(sKey) = 0 Then
- Exit For
- Else
- If objDic.exists(sKey) Then
- For j = 0 To iCnt
- arrData1(i, j + 8) = objDic(sKey)(j)
- Next
- End If
- End If
- Next
- rngData.Value = arrData1
- End Sub
复制代码 |
评分
-
1
查看全部评分
-
|