小编Epl*_*usL的帖子

月份函数抛出类型与VBA帮助文件中的示例代码不匹配

我检查了这里所有网站上,发现了几个解决方案,这一点,我试过,包括铸造NowCDate,但没有任何工程.

在Win7上使用带有Excel 2010的VBA编辑器.

即使是帮助部分中的示例代码也会抛出此错误,并且Month()函数中使用的日期将以数字形式显式初始化.

在这两种情况下,我尝试使用CDate()month()说法,这是行不通的.在我的原始代码中,我也尝试使用Date而不是Now,也没有效果.

这是我的原始代码,它在If条件上转换错误:

Function SetNextTaskNb()

    Dim seqNb As String
    seqNb = ThisWorkbook.Worksheets("Persistent").Range("A" & 1).Value

    Dim Nbs() As String
    Nbs = Split(seqNb, ".", 2)

    Dim month, currentNb, nextNb As Integer    
    month = CInt(Nbs(0))
    currentNb = CInt(Nbs(1))

    If month(Now) = month Then 
        nextNb = currentNb + 1
    Else
        nextNb = 1
    End If

    ThisWorkbook.Worksheets("Persistent").Range("A" & 1).Value = currentMonth + "." + nextNb
    ThisWorkbook.Worksheets("Sheet1").Range("A" & 1).Value …
Run Code Online (Sandbox Code Playgroud)

excel vba excel-vba type-mismatch

0
推荐指数
1
解决办法
909
查看次数

标签 统计

excel ×1

excel-vba ×1

type-mismatch ×1

vba ×1