简单的VBA宏,允许用户插入自定义编号

问题描述:

在我的宏输入29301到过滤器,我想启动一个对话框,其中用户可以输入自己的号码进行过滤。简单的VBA宏,允许用户插入自定义编号

Sub Macro3() 
ActiveSheet.Range("$A$1:$CL$293662").AutoFilter Field:=19, Criteria1:= _ 
    "=29301", Operator:=xlAnd 
End Sub 
+0

做一些类似'number = application.inputbox(“enter number to filter”)''然后在过滤器中使用'number'。 – findwindow

试试看。代码中的注释。

Public Sub test() 
    Dim retval 

    'Get a value, very simple input box 
    retval = InputBox("Please enter a number to filter by") 

    'Make sure the data is numeric 
    If IsNumeric(retval) = False Then 
     MsgBox "You didn't enter a number! Try again" 
     Exit Sub 
    End If 

    'Apply the filter 
    ActiveSheet.Range("$A$1:$CL$293662").AutoFilter Field:=19, Criteria1:="=" & retval 
End Sub 
+0

就是这样,感谢瑞恩。 – cam

+0

不客气! –