Excel精英培训网

 找回密码
 注册
数据透视表40+个常用小技巧,让你一次学会!
查看: 1485|回复: 2

[已解决]求助:判断E1单元格的日期是否存在于A列的代码出错

[复制链接]
发表于 2012-10-13 15:58 | 显示全部楼层 |阅读模式
详见附件,谢谢大家!
最佳答案
2012-10-13 16:26
本帖最后由 lisachen 于 2012-10-13 20:45 编辑

Sub d()
    Dim d As Object
    Set d = CreateObject("scripting.dictionary")
    For i = 1 To 99
        d(Cells(i, 1).Value) = ""
    Next i
    If d.exists(CDate(Cells(1, "e"))) Then
        MsgBox "yes"
    End If
End Sub

因为Cells(1, "e")是文本格式的,所以用CDate转换
zjdh d(Cells(1, "e").Value) = "" 这句不能加的,否则不存在的日期也会提示“yes” !说得对,是我测试时用的。忘了删除
日期.jpg

判断日期是否存在于A列的一个代码出错.zip

8.4 KB, 下载次数: 5

发表于 2012-10-13 16:26 | 显示全部楼层    本楼为最佳答案   
本帖最后由 lisachen 于 2012-10-13 20:45 编辑

Sub d()
    Dim d As Object
    Set d = CreateObject("scripting.dictionary")
    For i = 1 To 99
        d(Cells(i, 1).Value) = ""
    Next i
    If d.exists(CDate(Cells(1, "e"))) Then
        MsgBox "yes"
    End If
End Sub

因为Cells(1, "e")是文本格式的,所以用CDate转换
zjdh d(Cells(1, "e").Value) = "" 这句不能加的,否则不存在的日期也会提示“yes” !说得对,是我测试时用的。忘了删除

点评

d(Cells(1, "e").Value) = "" 这句不能加的,否则不存在的日期也会提示“yes” !  发表于 2012-10-13 18:01

评分

参与人数 1 +1 收起 理由
秋意正浓 + 1 赞一个!

查看全部评分

回复

使用道具 举报

发表于 2012-10-13 17:57 | 显示全部楼层
Sub d()
    Dim d As Object
    Set d = CreateObject("scripting.dictionary")
    For i = 1 To 99
        d(Cells(i, 1).Value) = ""
    Next
    If d.exists(Cells(1, "e").Value) Then
        MsgBox "yes"
    End If
End Sub
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|Archiver|Excel精英培训 ( 豫ICP备11015029号 )

GMT+8, 2024-3-29 17:21 , Processed in 0.466121 second(s), 13 queries , Gzip On, Yac On.

Powered by Discuz! X3.4

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表