Excel 从列中删除小于特定值的值

Excel 从列中删除小于特定值的值,excel,vba,Excel,Vba,我想写一个宏,如果列中的值小于工作表中其他地方指示的特定值,则从列中删除这些值 我的尝试 Sub clearsmall() Dim r As Range num1 = Cells(7, 5).Value For Each r In Selection If r.Value < num1 Then r.Clear End If Next End Sub 我需要如何更改代码?Sub clearsmall() Sub clearsmall() Dim cell As Range

我想写一个宏,如果列中的值小于工作表中其他地方指示的特定值,则从列中删除这些值

我的尝试

    Sub clearsmall()
Dim r As Range
num1 = Cells(7, 5).Value
For Each r In Selection
If r.Value < num1 Then
r.Clear
End If
Next
End Sub
我需要如何更改代码?

Sub clearsmall()
Sub clearsmall()
    Dim cell As Range, r As Range

    Set r= Range("C16:C92")
    num1 = Cells(7, 5).Value
    For Each cell In r
        If cell.Value < num1 Then cell.Clear
    Next
End Sub
变暗单元格作为范围,r作为范围 设置r=范围(“C16:C92”) num1=单元格(7,5)。数值 对于r中的每个单元格 如果cell.Value
您还可以将其缩短为

Sub clearsmall()
    Dim cell As Range

    Num1 = Cells(7, 5).Value
    For Each cell In Range("C16:C92")
        If cell.Value < num1 Then cell.Clear
    Next
End Sub
Sub-clearsmall()
暗淡单元格作为范围
Num1=单元格(7,5)。数值
对于范围内的每个单元格(“C16:C92”)
如果cell.Value

最后,您可能希望使用ClearContents而不是Clear,以便只清除单元格值,这会更快。这不会影响格式

@Timheinerz,你通过了吗?
Sub clearsmall()
    Dim cell As Range

    Num1 = Cells(7, 5).Value
    For Each cell In Range("C16:C92")
        If cell.Value < num1 Then cell.Clear
    Next
End Sub