首页 > 解决方案 > 在日期范围内查找日期VBA excel

问题描述

我对 VBA 非常陌生。在搜索日期范围内的日期后,我试图让 Excel 返回单元格地址。

我在 C 列中有一系列日期都设置为真实日期格式。

2018 年 1 月 12 日 2019 年 1 月 1 日 2019 年 1 月 2 日 ...

并在 D10 中单独约会。我想要一些 VBA 代码使用 D10 中的日期作为条件搜索 C 列,并返回结果的单元格地址。

在此先感谢您的帮助


编辑。

在 vba 的早些时候,我将 D10 定义为一个名为startingmonth 的日期变量。

这是我的代码。我只是使用 43435 作为文本作为测试,我想在这里使用起始月份(即 D10)但是当我用变量替换 43435 时,我收到错误 6 溢出。

Dim startingmonth As Date
startingmonth = Excel.Application.WorksheetFunction.EoMonth(ActiveCell.Offset(-2, 0).Value2, -1) + 1

Dim rgFound As Range
Set rgFound = Range("C:C").Find("43435")
MsgBox rgFound.Address

当前解决方法(来自活动单元格 D12)

ActiveCell.Offset(1, -1).Select

If ActiveCell.Value = startingmonth Then
MsgBox ActiveCell.Address
Else
GoTo Searchloop
End If

Searchloop:

ActiveCell.Offset(1, 0).Select

If ActiveCell.Value = startingmonth Then
MsgBox ActiveCell.Address
Else
GoTo Searchloop
End If

标签: excelvba

解决方案


推荐阅读