Excel VBA日历-提货日期命令问题

时间:2019-01-25 07:47:29

标签: excel vba

我正在做我的第一个VBA项目,我真的很困。

在我的Excel工作表上,我需要一个日期选择器。我使用的Excel版本没有日历,因此我使用下面链接中的代码创建了自己的日历(日历由L42创建,带有42个标签,依此类推):

Formatting MM/DD/YYYY dates in textbox in VBA

日历看起来就像图片中的日历一样,到目前为止一切正常。

enter image description here

在我的Excel电子表格上,我添加了一个代码,使日历仅在两个单元格E2和F2中弹出,分别代表数据的开始日期和结束日期。

Private Sub worksheet_selectionchange(ByVal target As Range)
If Not Application.Intersect(Range("E2"), target) Is Nothing Then
MyCalendar.Show
End If
If Not Application.Intersect(Range("F2"), target) Is Nothing Then
MyCalendar.Show
End If
End Sub

一切正常,仅当我单击这两个单元格时,日历才会弹出。 因此,当我单击E2时,将弹出日历,选择一个日期,然后弹出一个带有所选日期的消息框,单击确定将其关闭,然后关闭日历,但是单击的日期不会插入我的E2电池中。

我想我需要在select_label过程中使用以下代码,该代码将使我在日历中单击并在MsgBox中弹出的日期实际填充我的excel E2或F2单元格。

    Private Sub select_label(msForm_C As MSForms.Control)
        '/* Capture the selected date */
        Dim i As Integer, sel_date As Date
        i = Split(msForm_C.Name, "_")(1) - 1
        sel_date = FirstCalSun(curMonth) + i

        '/* Transfer the date where you want it to go */
        MsgBox sel_date

End Sub

非常感谢您的帮助。

谢谢。

0 个答案:

没有答案