vba 范围查找日期列
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/15677964/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Range Find Date Column
提问by Kazimierz Jawor
The below procedure sometimes gives wrong output. Can someone modify it such that when date to be searched is not available then it should increment the date by 1 and search again until it finds the available date.
下面的过程有时会给出错误的输出。有人可以修改它,以便当要搜索的日期不可用时,它应该将日期增加 1 并再次搜索,直到找到可用日期。
Example : If i search for "1/1/2012" and if its not available then it should increment the date to "2/1/2012" and process the search until it finds the match value and return range address if found.
示例:如果我搜索“1/1/2012”并且它不可用,那么它应该将日期增加到“2/1/2012”并处理搜索直到找到匹配值并返回范围地址(如果找到)。
Note : The range format "M/d/yyyy"
注意:范围格式“M/d/yyyy”
Sub test()
Dim rng As Range
Set rng = Sheet1.Range("A:A").Find("1/1/2012")
Debug.Print rng.Address
'output $A88
'"1/1/2012" is not available.
End Sub
回答by Kazimierz Jawor
Copy from comment to match the question as solved...
从评论中复制以匹配已解决的问题...
...try to add additional parameters of .Find
method:
...尝试添加.Find
方法的其他参数:
Set rng = Sheet1.Range("A:A").Find("1/1/2012", LookIn:=xlValues, LookAt:=xlWhole)