如果您希望使用 VBA 执行此操作,可以将以下宏添加到您的工作簿中:
编辑
您的评论表明您正在寻找前导零和尾随零,而不仅仅是像原始问题所暗示的那样尾随。如果是这种情况,您可以通过一个简单的条件语句来完成此操作,该语句检查 3 个零的位置(如果有的话)。
Format
如果可能的话,单元格Number type
删除前导零会简单得多。如果这是不可能的,那么这是实现这一目标的宏:
Public Sub CompareValues()
Dim rowCount As Integer, currentRow As Integer
Dim firstCellValue As String
Dim secondValValue As String
rowCount = Sheet1.Cells(Rows.Count, 1).End(xlUp).Row
Dim test As String
For currentRow = rowCount To 1 Step -1
'remove three leading or trailing 0's from value
test = Left(Cells(currentRow, 1).Value, 3)
If Left(Cells(currentRow, 1).Value, 3) = "000" Then
firstCellValue = Right(Cells(currentRow, 1).Value, Len(Cells(currentRow, 1).Value) - 3)
Else
firstCellValue = Left(Cells(currentRow, 1).Value, Len(Cells(currentRow, 1).Value) - 3)
End If
secondValValue = Cells(currentRow, 2).Value
If Not IsEmpty(firstCellValue) And Not firstCellValue = "" Then
If firstCellValue = secondValValue Then
Cells(currentRow, 1).Value = secondValValue
Else
Cells(currentRow, 1).EntireRow.Delete
End If
End If
Next
End Sub
宏之前
宏之后