假设我有以下琐碎的任务:
Range.Find()因此,我创建了一个代码,循环从1到30并写下每个月的第一个日期.然后我用Rows(1).Find(CDate("01.01.2016"))或者Rows(1).Find(DateSerial(2016,1,1))我认为我的任务几乎准备好了.
我运行代码,我在Excel 2010和Excel 2016中看到了这一点:
问题:
背后有什么理由吗?或者Range.Find()记录的功能是这样的吗?
Public Sub TestMe()
Cells.Clear
Dim cnt As Long
For cnt = 1 To 30
Cells(1, cnt) = DateAdd("M", cnt - 1, DateSerial(2016, 1, 1))
Cells(1, cnt).NumberFormat = "MMM-YY"
Next cnt
Dim foundRange As Range
Set foundRange = Rows(1).Find(CDate("01.01.2016"))
'Set foundRange = Rows(1).Find(DateSerial(2016, 1, 1)) 'the same false result
'Set foundRange = Rows(1).Find("01.01.2016") 'does not find anything
If Not foundRange Is Nothing Then
foundRange.Interior.Color …Run Code Online (Sandbox Code Playgroud)