如何比较单元格中的数据以查看它是错误、“0”作为文本还是任何其他值?
How can I compare the data in a cell to see if it is an error, "0" as text, or any other value?
我正在尝试在 VBA 中为 excel 编写一个 If 语句来查看单元格的值并确定它是否为“0”(单元格被格式化为文本),如果这是一个错误,或者除了这两个之外还有什么。
如果它不是“0”或错误,我想复制选择并将其粘贴到另一列中。
这是我的代码片段:
'Nested For Loop to Extract Values into Column G
For DCRNumOfParts = LastCellInColumn - 4 To 1 Step -1
Set SortCell = Cells(SortRow, 5)
SortCell.Select
IsCellError = IsError(Selection.Value)
'If Statement to determine if the cell value is 0 or error state
'If Selection.Value <> 0 Or VarType(ActiveCell.Value) <> vbError Then
If Selection.Value <> "0" And IsCellError <> True Then
Selection.Copy
Set CopyCell = Cells(SortRow, 7)
CopyCell.Select
ActiveSheet.Paste
End If
SortRow = SortRow + 1
Next DCRNumOfParts
我自己设法解决了这个问题,我通过执行以下操作处理了类型不匹配错误:
CellAsString = CStr(Selection.Value)
'If Statement to determine if the cell value is 0 or error state
'If Selection.Value <> 0 Or VarType(ActiveCell.Value) <> vbError Then
If Not IsError(Selection.Value) And CellAsString <> "0" Then
我正在尝试在 VBA 中为 excel 编写一个 If 语句来查看单元格的值并确定它是否为“0”(单元格被格式化为文本),如果这是一个错误,或者除了这两个之外还有什么。
如果它不是“0”或错误,我想复制选择并将其粘贴到另一列中。
这是我的代码片段:
'Nested For Loop to Extract Values into Column G
For DCRNumOfParts = LastCellInColumn - 4 To 1 Step -1
Set SortCell = Cells(SortRow, 5)
SortCell.Select
IsCellError = IsError(Selection.Value)
'If Statement to determine if the cell value is 0 or error state
'If Selection.Value <> 0 Or VarType(ActiveCell.Value) <> vbError Then
If Selection.Value <> "0" And IsCellError <> True Then
Selection.Copy
Set CopyCell = Cells(SortRow, 7)
CopyCell.Select
ActiveSheet.Paste
End If
SortRow = SortRow + 1
Next DCRNumOfParts
我自己设法解决了这个问题,我通过执行以下操作处理了类型不匹配错误:
CellAsString = CStr(Selection.Value)
'If Statement to determine if the cell value is 0 or error state
'If Selection.Value <> 0 Or VarType(ActiveCell.Value) <> vbError Then
If Not IsError(Selection.Value) And CellAsString <> "0" Then