Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/excel/25.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
从列中删除零并与其他列进行比较的Excel公式_Excel_Ms Office_Excel Formula - Fatal编程技术网

从列中删除零并与其他列进行比较的Excel公式

从列中删除零并与其他列进行比较的Excel公式,excel,ms-office,excel-formula,Excel,Ms Office,Excel Formula,我正在尝试应用Excel公式对Excel列进行排序,但无法找到它 excel条目如下所示: 如您所见,在第一列中,记录的末尾有000 1) 我需要忽略A栏最后的000,比较A栏和B栏的内容 a) If it matches, then remove the 000 from the Column A. b) If it does not matches, then delete the entire row OR make the content for both the col

我正在尝试应用Excel公式对Excel列进行排序,但无法找到它

excel条目如下所示:

如您所见,在第一列中,记录的末尾有000

1) 我需要忽略A栏最后的000,比较A栏和B栏的内容

   a) If it matches, then remove the 000 from the Column A.

   b) If it does not matches, then delete the entire row OR make the content for both the column as N/A.
请帮我解决这个问题,这个excel的内容非常庞大,因此手动操作是不可行的:(


谢谢,

如果第一列总是数字并且总是有3个零,那么只需除以1000进行比较


如果不是,则将第一个(长度-3)字符转换为字符串,并与第二列的字符串结果进行比较如果希望使用VBA执行此操作,则可以将以下宏添加到工作簿中:

编辑

您的评论指出,您正在寻找前导零和尾随零,而不是像原始问题所建议的那样只是尾随。如果是这样,您可以通过一个简单的条件语句来完成这一任务,该语句检查3个零的位置(如果有)

如果可能,将单元格
格式化
数字类型以删除前导零会简单得多。如果不可能,那么下面的宏正好实现了这一点:

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
在宏之前

在宏之后


非常感谢您的回复。如果每个单元格前面都有三个0,而不是最后一个,您能告诉我怎么办吗?我面临的情况是,在某些情况下,0也在前面:(此excel是一个巨大的excel,因此错过了前面的三个zore场景:(