【发布时间】:2018-10-04 21:22:18
【问题描述】:
目前,我从我们的一个数据库中收到每月转储,其中包含我们所有有效的公共交通订阅。将这些上传到 SAP 是我的任务,但只有与上个月不同的值。因此,应该选择所有新订阅,以及与上个月相比,不同列之一中的值之一不同的所有订阅。如果行完全一样,我就不需要了。
我收到的文件包含 7 列,A 列包含每个员工的唯一键。
我想使用 VBA 比较两个 excel 文件,方法是将上个月的文件粘贴到 Sheet1,将本月的文件粘贴到 Sheet2。我想找到那些相等的行并将它们从Sheet2 中删除。
我已经找到了一些执行此操作的 VBA 代码示例,但似乎没有任何工作正常。下面这个是我用的最后一个,下面这行代码Do While Not IsEmpty(wsA.Range(keyColA & intRowCounterA).Value)出现语法错误。
Sub CleanDupes()
Dim wsA As Worksheet
Dim wsB As Worksheet
Dim keyColA As String
Dim keyColB As String
Dim rngA As Range
Dim rngB As Range
Dim intRowCounterA As Integer
Dim intRowCounterB As Integer
Dim strValueA As String
keyColA = "A"
keyColB = "B"
intRowCounterA = 1
intRowCounterB = 1
Set wsA = Worksheets("Sheet1")
Set wsB = Worksheets("Sheet2")
Do While Not IsEmpty(wsA.Range(keyColA & intRowCounterA).Value)
intRowCounterB = 1
Set rngA = wsA.Range(keyColA & intRowCounterA)
strValueA = rngA.Value
Do While Not IsEmpty(wsB.Range(keyColB & intRowCounterB).Value
Set rngB = wsB.Range(keyColB & intRowCounterB)
If strValueA = rngB.Value Then
'Code to delete row goes here, but I'm not sure exactly'
'what it is.'
wsB.Range(Rows(intRowCounterB)).EntireRow.Delete
intRowCounterB = intRowCounterB - 1
End If
intRowCounterB = intRowCounterB + 1
Loop
intRowCounterA = intRowCounterA + 1
Loop
结束子
有什么想法吗?
尼克
【问题讨论】:
-
如果您尝试了不起作用的代码,您应该将它包含在您的帖子中,并准确解释它是如何不起作用的。
-
抱歉,对 VBA 和本网站来说还是很陌生。我更新了我原来的问题。
标签: vba excel duplicates