我有两个范围,我比较找到不比较的值。这些值需要粘贴到新单元格中。我的代码工作得很完美,但由于某些原因,如果单元格值只是数字,它将无法工作。
请参阅下文。
Sub RangeCompare2()
Dim Rg1 As Range, Rg2 As Range, c1 As Range, rgPaste2 As Range
Dim lngRowOffset3 As Long
On Error Resume Next
lngRowOffset3 = 0
Set Rg1 = Worksheets("Bridget Madumo").Range("AQ40:AQ70")
Set Rg2 = Worksheets("Bridget Madumo").Range("C69:C122")
Set rgPaste2 = Worksheets("BM CS").Range("C102")
Set rgPaste2 = rgPaste2.Cells(1, 1)
On Error GoTo 0
For Each c1 In Rg1.Cells
If Application.WorksheetFunction.CountIf(Rg2, c1.Value & "*") = 0 Then
rgPaste2.Offset(lngRowOffset3).Value = c1.Value
rgPaste2.Offset(lngRowOffset3, 1).Value = c1.Offset(, 1).Value
rgPaste2.Offset(lngRowOffset3, 2).Value = c1.Offset(, 2).Value
rgPaste2.Offset(lngRowOffset3, 3).Value = c1.Offset(, 3).Value
lngRowOffset3 = lngRowOffset3 + 1
End If
Next c1
Application.CutCopyMode = False
End Sub