我正在尝试创建一个宏,该宏将检查 A 列(客户端 ID 号)的值,识别重复值,然后,一旦找到重复值,执行嵌套的 If/Then 检查,该检查将基于某些单元格返回值它发现了什么。如果重复值对应行的F列(程序描述)包含子字符串“UPGRADE”,则应使原始值对应行的J列文本与重复值中F列的文本相同。然后,应该删除重复的行,但我还没有走那么远。
这是我到目前为止所拥有的-
Dim lastrow As Long
lastrow = Cells(Rows.Count, "A").End(xlUp).Row 'find last row in column A
For x = 1 To lastrow
If Cells(x, 1).Value <> ActiveCell.Value Then 'Check if cell in column A contains the same value as the activated cell
For y = 1 To lastrow
If Cells(y, 1).Value = Cells(x, 1).Value Then 'Compares cell against each value in column A. If there is a match, the do the following:
If Cells(y,6).Value <> "UPGRADE" Then 'Checks if duplicate value contains "UPGRADE"
Cells (x,10).Value= Cells(y,10).Value 'If this value is found, copy the value of the duplicate program name into a specified column for that program type in row x.
Else Cells(x,12).Value=Cells(y,12).Value 'If the value is not found, copy the program type into a separate column for that program type in row x.
End If
Next y
End If
Next x
我尝试运行这个程序并收到一个“Next without For”错误,但我不确定如何解决它,或者如果我这样做了代码是否可以工作。任何帮助将不胜感激。
目前还不清楚您想要做什么,但以下对您有用吗?
Public Sub checkDup()
Dim lastrow As Long, x As Long, y As Long
lastrow = Cells(rows.Count, "A").End(xlUp).Row 'find last row in column A
For x = 1 To lastrow
'If Cells(x, 1).Value <> ActiveCell.Value Then 'Check if cell in column A contains the same value as the activated cell
For y = x + 1 To lastrow
If Cells(y, 1).Value = Cells(x, 1).Value Then 'Compares cell against each value in column A. If there is a match, the do the following:
If Cells(y, 6).Value <> "UPGRADE" Then 'Checks if duplicate value contains "UPGRADE"
Cells(x, 10).Value = Cells(y, 6).Value 'If this value is found, copy the value of the duplicate program name into a specified column for that program type in row x.
'Else
'Cells(x, 12).Value = Cells(y, 12).Value 'If the value is not found, copy the program type into a separate column for that program type in row x.
End If
End If
Next y
'End If
Next x
End Sub
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句