Vba &引用;运行时错误13:类型不匹配“;
我有一个VBA程序,它允许用户在活动Excel工作表的第一行输入名称(整数/字符串等)来编写标题。在输入被写入之后,我需要在相邻的单元格中写入输出 逐行遍历宏,我相信这是给出错误的问题行 运行时错误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
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
。