vba - VBA 代码基于用户输入框应用过滤器,用于列字母数字和日期
问题描述
我想编写询问用户他们想要过滤“哪一列”的 vba 代码;然后是他们想要过滤该列的“什么日期”(即 mm/dd/yyyy 之后的任何日期)
就像是:
Sub FilterByInput()
Dim iPutFound As Range
Dim mycol As String
Dim mydate As String
mycol = Application.InputBox("Enter alpha-numeric of Column to be filtered -ie. AP3", Type:=2)
mycol = Range(mycol & 1).Column
mydate = Application.InputBox("Enter date since last update was ran- mm/dd/yyyy", Type:=2)
Application.ScreenUpdating = False
ActiveSheet.Range("$A$3:$DK$11000").AutoFilter Field:=mycol, Criteria1:=">" & mydate, Operator:=xlFilterValues
'The code will resume with copying and pasting the filtered results to another sheet, etc
End Sub
我收到一个运行时错误:“范围类的自动筛选方法失败。” 我的标题行位于第 3 行。我尝试在运行代码之前关闭过滤器,但这也不起作用。任何帮助是极大的赞赏。
这是我对编辑所做的:
Dim ws As Worksheet: Set ws = ActiveSheet
Dim iPutFound As Range
Dim mycol As String
Dim myrng As Range
Dim mydate As String
mycol = Application.InputBox("Enter alpha-numeric of Column to be filtered -ie. M", Type:=2)
Set myrng = Range(mycol & 1).Column
mydate = Application.InputBox("Enter date since last update was ran- mm/dd/yyyy", Type:=2)
Application.ScreenUpdating = False
ActiveSheet.Range(mycol & 1).Column.AutoFilter Field:=mycol, Criteria1:=">" & mydate, Operator:=xlFilterValues
解决方案
推荐阅读
- c# - 使用方法链接将大类拆分为较小的类
- padding - 写入 pcap 文件时 Scapy 以太网填充层丢失
- scala - Spark:复制每一行但改变一列值
- html - 我需要一个 div 在页面底部对齐。div 中包含 5 个其他 div
- android - Ajax成功功能在android webview上不起作用
- javascript - 是否可以创建一个带有两个参数的函数(地图的键值对,首选项)并在首选项为“否”时删除键值对?
- r - 从列变量中删除前缀字母
- javascript - 动态合并不同数组中的所有对象(附加名称而不是忽略)
- swift - 如何在 SwiftUI 中使图像的容器宽度达到 100%?
- php - 将 JSON 数组数据导入 MySQL