Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/vba/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Vba &引用;运行时错误13:类型不匹配“;_Vba_Excel - Fatal编程技术网

Vba &引用;运行时错误13:类型不匹配“;

Vba &引用;运行时错误13:类型不匹配“;,vba,excel,Vba,Excel,我有一个VBA程序,它允许用户在活动Excel工作表的第一行输入名称(整数/字符串等)来编写标题。在输入被写入之后,我需要在相邻的单元格中写入输出 逐行遍历宏,我相信这是给出错误的问题行 运行时错误13:类型不匹配 这是相关的功能: Sub enteroutputs() title = "K-Map Program" outputnum = Application.InputBox("How many outputs?", title) If IsNumeric(outputnum) = Fal

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

逐行遍历宏,我相信这是给出错误的问题行

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

这是相关的功能:

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
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
inputnum在该函数之前执行的函数中定义:

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
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

结束Sub

您只是错过了一些东西

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
只需在
Next
Call-enteroutput
之间添加:

inputnum = counter - 1

另一个可以通过
Option Explicit
来防止的错误迫使您声明正在使用的变量:
Dim inputnum为Integer