簡體   English   中英

“運行時錯誤13:類型不匹配”

[英]“Run time-error 13: Type Mismatch”

我有VBA程序,允許用戶在活動Excel工作表的第一行中輸入名稱(整數/字符串/等)以編寫標題。 寫入輸入后,我需要將輸出寫入相鄰的單元格中。

逐行逐步執行宏,我相信這是導致錯誤的問題所在

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

結束子

你只是錯過了一些東西

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM