[英]Clear Cell Contents of range if Contes = 0
我想清除基于范围的单元格内容。 我想我快到了。
Dim R As Range
Dim myRange As Range
LastRow = Range("A" & Rows.Count).End(xlUp).Row
Set myRange = Range("Y2:Y" & LastRow)
For Each R In myRange
If R = 0 Then
cell.ClearContents
End If
Next
End Sub
所有帮助表示赞赏。
问题是您的单元格引用。 更改cell.
到R.
R
是您正在循环的范围内的单元格,因此如果R = 0
,请清除它。
Sub clearR()
Dim R As Range
Dim myRange As Range
lastRow = Range("A" & rows.count).End(xlUp).Row
Set myRange = Range("Y2:Y" & lastRow)
For Each R In myRange
If R = 0 Then
R.ClearContents
End If
Next
End Sub
如果 Y 列不是公式,则另一个没有循环的解决方案应该可以工作。
Sub clearR()
Dim LastRow As Long
LastRow = Range("A" & Rows.Count).End(xlUp).Row
Range("Y2:Y" & LastRow).Replace 0, "", xlWhole
End Sub
你可以使用:
Sub Macro1()
Dim LastRow As Long
With ThisWorkbook.Worksheets("Sheet1")
'Find last row
LastRow = .Range("A" & .Rows.Count).End(xlUp).Row
'Clear replace 0 with nothing in the specific range
.Range("Y2:Y" & LastRow).Replace What:="0", Replacement:="", LookAt:=xlWhole
End With
End Sub
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.