|
楼主 |
发表于 2024-1-6 16:52
|
显示全部楼层
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
不好意思过了这么久,再来请教一点事情,就是当左边前面三列数据等于右边前面三列数据数据一致时,对应的红色框框那两列D列,K列的数据,也一并清楚,要怎么修改呢- Public Sub dsm()
- '找出相同数据并删除
- Dim m As Integer, n As Integer, r1 As Integer, r2 As Integer
- Dim Arr(), Brr(), Crr()
- Dim ds As Object
- Set ds = CreateObject("Scripting.Dictionary")
- r1 = Range("b65536").End(xlUp).Row
- r2 = Range("i65536").End(xlUp).Row
- Arr = Range("a3:c" & r1).Value
- Brr = Range("h3:j" & r2).Value
- For n = 1 To r1 - 2
- ds(Arr(n, 2)) = n
- Next
- ReDim Crr(1 To r2 - 2, 1 To 3)
- For m = 1 To r2 - 2
- If ds.exists(Brr(m, 2)) Then
- n = ds(Brr(m, 2))
- For i = 1 To 3
- If Arr(n, 1) = Brr(m, 1) And Arr(n, 3) = Brr(m, 3) Then
- Arr(n, i) = "": Brr(m, i) = ""
- Else
- Crr(m, i) = Arr(n, i)
- End If
- Next
- End If
- Next
- Application.EnableEvents = False
- Application.ScreenUpdating = False
- Range("a3:c" & r1).Value = Arr
- Range("h3:j" & r2).Value = Brr
- Range("k3:m" & r2).Value = Crr
- Application.EnableEvents = True
- Application.ScreenUpdating = True
- End Sub
- Public Sub dsm_2()
- '找出相同数据并删除,将找不到的单号,或者是单号一致数据不一致的提取到另一个表格
- Dim m As Integer, n As Integer, r1 As Integer, r2 As Integer
- Dim Arr(), Brr(), Crr(), Drr(), r%, ra%
- Dim ds As Object
- Set ds = CreateObject("Scripting.Dictionary")
- r1 = Range("b65536").End(xlUp).Row
- r2 = Range("i65536").End(xlUp).Row
- Arr = Range("a3:c" & r1).Value
- Brr = Range("h3:j" & r2).Value
- For n = 1 To r1 - 2
- ds(Arr(n, 2)) = n
- Next
- ReDim Crr(1 To r2 - 2, 1 To 7), Drr(1 To r1 - 2, 1 To 3)
- For m = 1 To r2 - 2
- If ds.exists(Brr(m, 2)) Then
- n = ds(Brr(m, 2))
- If Arr(n, 1) = Brr(m, 1) And Arr(n, 3) = Brr(m, 3) Then
- Arr(n, 1) = "": Arr(n, 3) = ""
- Else
- r = r + 1
- If Arr(n, 1) <> "" Then ra = ra + 1
- For i = 1 To 3
- Crr(r, i) = Brr(m, i)
- If Arr(n, 1) <> "" Then
- Crr(r, i + 4) = Arr(n, i)
- Drr(ra, i) = Arr(n, i)
- End If
- Next
- End If
- Else
- r = r + 1
- For i = 1 To 3
- Crr(r, i) = Brr(m, i)
- Next
- End If
- Next
- For n = 1 To r1 - 2
- If Arr(n, 1) <> "" Then
- ra = ra + 1
- For i = 1 To 3
- Drr(ra, i) = Arr(n, i)
- Next
- End If
- Next
- Application.EnableEvents = False
- Application.ScreenUpdating = False
- Range("l2:n2").Value = Range("a2:c2").Value
- Range("a3:c" & r1).Value = Drr
- Range("h3:n" & r2).Value = Crr
- Range("l2:n" & r + 2).Borders.LineStyle = 1
- Application.EnableEvents = True
- Application.ScreenUpdating = True
- End Sub
复制代码
|
-
|