excel - VBA Application.InputBox 验证。只在一定范围内选择
问题描述
我正在寻找一个输入框供用户选择一个单元格,宏将通过用户选择过滤一些外部数据。
我想为选择添加验证,以便用户只能选择一个值为“TRUE”的单元格,并且只能在某个范围内,例如列 Range("J4:J100")
到目前为止的代码:
Dim rng As Range
Set rng = Range("J4:J100")
Dim criteria1 As Range
Set criteria1 = Application.InputBox("Select a range", "Obtain Range Object", Type:=8)
Dim criteria2 As String
criteria2 = criteria1.Offset(0, -9)
Dim ws As Worksheet
Set ws = Worksheets("Reference_log")
ws.Select
Dim LastRow As Long
LastRow = ws.Cells(ws.Rows.Count, "A").End(xlUp).Row
Dim LastColumn As Long 'Find the last non-blank cell in row 2
LastColumn = Cells(2, Columns.Count).End(xlToLeft).Column
Set Rng1 = Cells(2, 8)
Set Rng2 = Cells(LastRow, LastColumn)
ActiveSheet.Range(Rng1, Rng2).AutoFilter Field:=2, criteria1:=Array("*" & criteria2 & "*"), Operator:=xlFilterValues
解决方案
推荐阅读
- json - 如何将标头添加到 JSON 以识别数组值的数组名称
- selenium - Selenium Chrome 浏览器 org.openqa.selenium.WebDriverException:等待驱动程序服务器启动超时
- asp.net-mvc - IIS 应用程序池重置 - 站点性能影响
- java - Spring boot userRepository.findAll() 显示次数过多导致stackoverflow错误
- redux - Redux-Thunk - 如何等待动作创建者完成
- asp.net - ASP 身份核心 GeneratePasswordResetTokenAsync 已过期
- tensorflow - 如何解决张量流中没有“估计器”的问题?
- python - 在python中修改标头内容类型后如何返回http响应
- git - 如何将 git lfs 与 Travis CI gh-pages deploy 一起使用?
- vim - Vim 错误格式字符串以在 QuickFix 中显示消息,删除其中的一部分