excel中的宏显示错误

时间:2016-05-24 08:06:43

标签: excel macros

Sub Month_Update()
    Dim dDate As Date
    dDate = Range("$C$1").Value
    Range("$E$1").Value = _
    DateSerial(Year(dDate), _
    Month(dDate) + 1, Day(dDate))
End Sub

运行时错误:13
类型不匹配

1 个答案:

答案 0 :(得分:0)

您可能遇到模块访问另一张表上的数据的问题。请尝试以下操作来指定您要从中提取的确切工作表:

Sub Month_Update()
    Dim ws As Worksheet
    Set ws = Excel.Sheets("Sheet1") 'Replace This Sheet1 Value with the Name of the Sheet that the data is on
    Dim dDate As Date
    dDate = ws.Range("$D$1").Value
    ws.Range("$E$1").Value = _
    DateSerial(Year(dDate), _
    Month(dDate) + 1, Day(dDate))
End Sub