|
这类有格式的最好当然是用sql语句来写,简单容易,也就是一行语句
- Sub marco()
- Dim a(1 To 4)
- Set dic = CreateObject("Scripting.Dictionary")
- For i = 2 To [n1].CurrentRegion.Rows.Count
- If Not dic.exists(Cells(i, "N").Text) Then
- a(1) = Cells(i, "O").Text
- a(2) = Cells(i, "P").Text
- a(3) = Cells(i, "Q").Text
- a(4) = Cells(i, "R").Text
- dic.Add Cells(i, "N").Text, a
- End If
- Next
- For i = 2 To [a1].CurrentRegion.Rows.Count
- If dic.exists(Cells(i, "a").Text) Then
- Cells(i, "B") = dic(Cells(i, "A").Text)(2)
- Cells(i, "d") = dic(Cells(i, "A").Text)(1)
- Cells(i, "e") = dic(Cells(i, "A").Text)(4)
- Cells(i, "f") = dic(Cells(i, "A").Text)(3)
- End If
- Next
- End Sub
复制代码 |
|