用于从列中删除零并与其他值进行比较的Excel公式
我试图应用Excel公式来sortingExcel列,但不能拿出来。
excel条目如下所示:
正如你所看到的,在第一栏中logging最后有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的内容是一个巨大的,因此手动做是不可行的:(
谢谢,
如果您正在使用VBA执行此操作,可以将以下macros添加到您的工作簿:
编辑
您的评论指出,您正在寻找前导和尾随零,而不仅仅是像原来的问题所示。 如果是这样的话,你可以通过一个简单的条件语句来完成这个任务,如果有的话,检查3个零点在哪里。
如果可能的话, Format
单元格Number type
以删除前导零就简单多了。 如果这是不可能的,那么这就是实现这个目标的macros:
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
macros观之前
macros后
如果第一列总是数字并且总是有3个零,那么简单地除以1000并进行比较。
如果不是,则转换为string,然后将substr转换为第一个(长度为-3)的字符,并与第二列的string结果进行比较