如何在Excel VBA中使match()与日期一起工作? [英] How to make match() work with date in excel vba?
本文介绍了如何在Excel VBA中使match()与日期一起工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在使match()在excel VBA中工作时遇到问题.代码是:
I'm having problem making the match() work in excel VBA. The code is:
x = Application.Match("Sep 2008", Range("F1:F1"), 0)
单元格F1中的值为2008年9月1日.
The value in cell F1 is 9/1/2008.
即使我将2008年9月更改为9/1/2008,它仍然不会返回任何值.
Even if I changed Sep 2008 to 9/1/2008, it still doesn't return any value.
有什么想法要解决吗?
推荐答案
您最好的选择是使用.Find()
.如果找到,将返回range
,否则将返回nothing
.
Your best bet is to use .Find()
. This will return a range
if found or nothing
if not.
Set x = Range("F1:F1").Find(CDate("Sept 2008"), , , xlWhole)
如果您需要列号:
x = Range("F1:F1").Find(CDate("Sept 2008"), , , xlWhole).Column
未捕获到
Sub test()
Dim y As Date, x As Variant, c As Long
y = CDate("Sep 2008")
Set x = Range("1:1").Find(y, , , xlWhole)
If Not x Is Nothing Then
c = x.Column '<~~found
Else
Exit Sub 'not found
End If
End Sub
这篇关于如何在Excel VBA中使match()与日期一起工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文