vba - 在表中查找特定记录
问题描述
我希望只找到某些记录并相应地处理它们。我有一个名为的表Locations
,其中一列标记为Location
。目前,当我运行宏时,我的代码会处理所有位置;但是,我想编写只运行某些位置(范围)的宏的变体。位置值都是 2 个字母后跟 5 个数字。示例:CA10020
我想要做的是提示开始和结束位置值,然后只处理那些。示例:CA10001 到 CA13240 这些值之前和之后的所有内容都将被忽略......但这些值以及它们之间的所有内容都将被处理。
通常我很清楚从哪里开始,通过反复试验我可以弄清楚其余的。在这种情况下,我不知道从哪里开始。如您所知,我不是 VBA 专家。
我目前有这段代码可以处理我现在不需要做的所有记录:
For i = 1 To Range("Locations").Rows.Count
Range("F3").Value = Range("Locations[Location]")(i)
'I have other code here that handles the new value of cell F3
Next i
更新:我添加了这段代码:
Dim Start_Location As Variant
Dim End_Location As Variant
Start_Location = InputBox("What is the starting location?")
End_Location = InputBox("What is the ending location?")
...但我现在不知道如何处理这些值。
解决方案
Dim Start_Location As Variant
Dim End_Location As Variant
Start_Location = InputBox("What is the starting location?")
End_Location = InputBox("What is the ending location?")
For i = 1 To Range("Locations").Rows.Count
If Range("Locations[Location]")(i) >= Start_Location And Range("Locations[Location]")(i) <= End_Location Then
Range("F3").Value = Range("Locations[Location]")(i)
'Code to handle the new value of cell F3
End If
Next i
推荐阅读
- python - 光学字符识别。字符分割阶段
- powershell - PowerShell 查找和替换文件问题
- python - Perl 相当于 Python for 循环?
- vba - 查找两个日期之间的年数时,DateDiff 不起作用
- r - 从 Shiny 的列表中选择输入
- mysql - sql查询按顺序返回每个组ID的单个记录
- react-native - 具有选定行的平面列表将位于同一位置,其他行滚动 - React-Native
- enterprise-architect - Enterprise Architect 不是一个有效的名字
- html - 具有 Flex 布局的角扩展面板和主体未对齐
- bash - 删除 bash 变量中标记之间的字符