2015-12-12 58 views
-1

我有VBA程序,它允許用戶在活動Excel工作表的第一行輸入名稱(整數/字符串/等)來編寫標題。寫入輸入後,我需要將輸出寫入相鄰單元。「運行時間錯誤13:類型不匹配」

通過線宏行步進,我相信這是問題的線,給出了錯誤

運行時錯誤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

另一個錯誤Option Explicit'強制你聲明你正在使用的變量:'D im inputnum As Integer'。 –

回答

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 
相關問題