Range.Find not making a difference between January and November (February and December) in VBA Excel

后端 未结 3 700
忘了有多久
忘了有多久 2020-11-29 12:26

Let\'s say that I have the following trivial task:

  • Write the first date of the months from January 2016 to June 2018 on a row
  • Find 01-January-2016 and
3条回答
  •  执笔经年
    2020-11-29 13:20

    I've found CDate to misbehave from time to time. This code appears to convert your date to a string first, not the numeric representation of the date. That conversion happens after you find the string. Since you mentioned it skips the first cell then the first date containing that string is 11/1/16.

    debug.print cdate("01/01/16")
    1/1/16
    
    Set foundRange = Rows(1).Find(CDate(#1/1/2016#))
    Debug.Print foundRange.Value2
    42675
    

提交回复
热议问题