Excel宏运行时触发Run-time Error '6'溢出错误求助
Excel VBA宏溢出错误:比较最早日期时触发Run-time Error '6'
我正在编写一个Excel宏,功能是基于三个日期中的最早日期执行操作,目前仅完成基础框架,用MsgBox做测试。宏代码如下:
Sub HighlightNextEDM() Dim LastDate1 As Date Dim LastDate2 As Date Dim LastDate3 As Date Dim OldestDate As Date LastDate1 = Sheet1.Range("F11") LastDate2 = Sheet1.Range("F12") LastDate3 = Sheet1.Range("F13") OldestDate = Application.WorksheetFunction.Min(LastDate1, LastDate2, LastDate3) MsgBox "LastDate1 = " & LastDate1 & vbNewLine & _ "LastDate2 = " & LastDate2 & vbNewLine & _ "LastDate3 = " & LastDate3 & vbNewLine & _ "OldestDate= " & OldestDate If OldestDate = LastDate1 Then MsgBox "LastDate1 is the oldest!" ElseIf OldestDate = LastDate2 Then MsgBox "LastDate2 is the oldest!" ElseIf OldestDate = LastDate3 Then MsgBox "LastDate3 is the oldest!" End If End Sub
单元格F11的值为1/1/2025 12:25:00 PM,F12的值为12/15/2024 8:35:00 AM,F13的值为3/1/2025 9:02:00 AM。
运行宏时,第一个显示所有日期的MsgBox可正常工作,但执行到If OldestDate = LastDate1 Then行时,触发Run-time Error '6'溢出错误。我尝试过将数据类型改为Double、赋值时使用*.Value*、将值转换为字符串等方法,均未解决问题,恳请各位提供帮助!
内容的提问来源于stack exchange,提问作者Chi-town Brad
相关产品推荐
相关产品推荐

