首页 文章

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

提问于
浏览
-1

我有VBA程序,允许用户在活动Excel工作表的第一行输入名称(整数/字符串/等)来编写 Headers . 写入输入后,我需要在相邻的单元格中写入输出 .

逐行逐行,我相信这是产生错误的问题行

运行时错误13:输入不匹配

Cells(1, counter + inputnum) = outputnum

这是相关的功能:

Sub enteroutputs()
title = "K-Map Program"
outputnum = Application.InputBox("How many outputs?", title)
If IsNumeric(outputnum) = False Then
    problem = "output"
    Call notnum
End If

For counter = 1 To outputnum
    outputnum = Application.InputBox("Enter output name.", title)
    Cells(1, counter + inputnum) = outputnum
Next
Dim ok
ok = MsgBox("Enter outputs in " & ActiveSheet.Name & " .", vbOKOnly)
End Sub

inputnum在此函数之前执行的函数中定义:

Sub enterinputs()
title = "K-Map Program"
inputnum = Application.InputBox("How many inputs?", title)
If IsNumeric(inputnum) = False Then
    problem = "input"
    Call notnum
End If

For counter = 1 To inputnum
    inputnum = Application.InputBox("Enter input name.", title)
    Cells(1, counter) = inputnum
Next
Call enteroutputs

结束子

1 回答

  • 2

    你只是错过了什么

    Sub enterinputs()
    title = "K-Map Program"
    inputnum = Application.InputBox("How many inputs?", title)
    If IsNumeric(inputnum) = False Then
        problem = "input"
        Call notnum
    End If
    ' ~~~~ here inputnum is numeric  ~~~~ 
    For counter = 1 To inputnum
        inputnum = Application.InputBox("Enter input name.", title) ' ~~~~ here inputnum is not! ~~~~ 
        Cells(1, counter) = inputnum
    Next
    Call enteroutputs 'while inputnum is NOT numeric
    Exit Sub
    

    只需在 NextCall enteroutputs 之间添加:

    inputnum = counter - 1
    

相关问题