|
楼主 |
发表于 2022-12-29 16:32
|
显示全部楼层
- Sub 删除多次出现的()
- Dim s, brr, i1%
- Dim k1
- Dim arr, crr, d, m%, n%
- arr = Sheets("重复数据").Range("a3:o" & Cells(Rows.Count, "d").End(xlUp).Row)
- n = Sheets("重复数据").Cells(Rows.Count, "d").End(xlUp).Row
-
- ReDim brr(1 To UBound(arr), 1 To UBound(arr, 2))
- Set d = CreateObject("scripting.dictionary")
- For i = 1 To UBound(arr)
- s = arr(i, 2) & "|" & arr(i, 4)
- d(s) = d(s) + 1
- Next
- For i = 1 To UBound(arr)
- s = arr(i, 2) & "|" & arr(i, 4)
- If d(s) = 1 Then
- m = m + 1
- For j = 1 To UBound(arr, 2)
- brr(m, j) = arr(i, j)
- Next
- End If
- If d(s) > 1 Then
- s = arr(i, 2) & "|" & arr(i, 4)
- For Each sh In Sheets
- If sh.Name = arr(i, 8) Then
- k1 = sh.Range("d65536").End(xlUp).Row
- crr = sh.Range("a3:o" & k1)
- For i1 = 1 To UBound(brr)
- If crr(i1, 2) & "|" & crr(i1, 4) = s Then
- sh.Range("a" & i1).EntireRow.Delete: shift = xlUp
- End If
- Next
- End If
- Next
- End If
- Next
- Sheets("重复数据").[a3].Resize(n, 15).ClearContents
- Sheets("重复数据").[a3].Resize(m, UBound(brr, 2)) = brr
- Sheets("重复数据").[a3].Resize(m, UBound(brr, 2)).Borders.LineStyle = 1
- End Sub
- 老师 删除“重复数据”表格中的 身份证号码和姓名 同时出现多次的数据 比如这两个数据 <img src="https://club.excelhome.net/forum.php?mod=image&aid=2846649&size=300x300&key=afa58ef65a957a08&nocache=yes&type=fixnone" border="0" aid="attachimg_2846649" alt="">出现了两次 则把他们全部删除 并且在其他三个表格中 找到这些数据 并且也删除掉相应的整行数据,个人感觉代码思路没有错误,就是在运行的时候出现小标越界,麻烦老师再次帮忙 谢谢
复制代码 |
|