Excel精英培训网

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

[已解决]求助 vba match里today()的用法

[复制链接]
发表于 2015-12-3 08:53 | 显示全部楼层 |阅读模式
本帖最后由 chensir 于 2015-12-3 12:56 编辑

j = Application.WorksheetFunction.Match(Date, Columns("A"), 0)
是不是 date用法有误,我这里如果用个Range("I11")就可以。
A列是日期行,我想取得当天在日期行所在的位置号

最佳答案
2015-12-3 09:33
'调用工作表函数中的Match方法
Sub test1()
    Dim x
    On Error Resume Next
    x = Application.WorksheetFunction.Match(CLng(Date), Columns("A:A"), 0)
    If Err.Number = 1004 Then x = "没找到"
    Err.Clear
    MsgBox x
End Sub

'Range.Find 方法
Sub test2()
    Dim rng As Range
    Set rng = Range("a:a").Find(Date)
    If rng Is Nothing Then MsgBox "没找到" Else MsgBox rng.Row
End Sub


当然,还可通过循环该区域,通过判断来得到结果。
360反馈意见截图162511219713084.jpg
发表于 2015-12-3 09:33 | 显示全部楼层    本楼为最佳答案   
'调用工作表函数中的Match方法
Sub test1()
    Dim x
    On Error Resume Next
    x = Application.WorksheetFunction.Match(CLng(Date), Columns("A:A"), 0)
    If Err.Number = 1004 Then x = "没找到"
    Err.Clear
    MsgBox x
End Sub

'Range.Find 方法
Sub test2()
    Dim rng As Range
    Set rng = Range("a:a").Find(Date)
    If rng Is Nothing Then MsgBox "没找到" Else MsgBox rng.Row
End Sub


当然,还可通过循环该区域,通过判断来得到结果。
回复

使用道具 举报

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

本版积分规则

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

GMT+8, 2024-4-20 21:06 , Processed in 0.263828 second(s), 10 queries , Gzip On, Yac On.

Powered by Discuz! X3.4

Copyright © 2001-2020, Tencent Cloud.

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