明确声明的变量上的VBA类型不匹配13

时间:2014-10-17 07:07:11

标签: excel vba excel-vba

我现在有这个代码工作了一个月,它突然开始在我标记的行上抛出类型不匹配13。我一直在寻找一天,所有相关问题都是单元格格式或与对象相关的。

我认为我的问题不存在,而且看起来很简单,让我感到恶心,看不到它。

我尝试了什么:

使用了带有类型的application.inputbox方法,将所述变量声明为整数,变量而不是double,完全省略了使用0使其成为20并仍然得到了错误。代码有效,除非您输入0或无论如何将变量声明为零。这段代码已经工作了一个多月了。有什么问题?

编辑:更多信息

Sub Farincal_OPC_hamyuzde_vs_giriş()

Dim dbs1 As String
Dim dbis1 As String
Dim kayek1 As String
Dim kdn1 As String
Dim ph As Integer
Dim l As Integer
Dim dd As Integer
Dim ctf As Integer
Dim farin As Double
Dim farinper(18) As Double
Dim a As Integer

dd = MsgBox("question?", vbYesNo)
If dd = vbYes Then GoTo 13
If dd = vbNo Then GoTo 789


13


a = 1                'this resets the array
For a = 1 To 18
farinper(a) = 0
Next a
86

farin = InputBox("0 - PREMIX" & vbNewLine & "1 - etc") 'this holds the choice's number on farin

'THE TYPE MISMATCH HAPPENS ON THE LINE BELOW, AS SOON AS IT CHECKS OUT TO BE 0

    If farin = 4 Or farin = 5 Then 'this is used for the other choices which i deleted above.

'Code DOES NOT continue the line below, type mismatch happens as soon as the above line is run

    a = MsgBox("warning", vbExclamation)

    GoTo 86   'PREMİX CHECK!!!!
    End If
    If farin = 0 Then sheet1.Cells(28, 3) = InputBox("question")
    If farin > 18 Or farin < 0 Then
    MsgBox ("you are wrong")
    GoTo 86
    End If


a = 0
For a = 0 To 18

788
        If farin = a Then farinper(a) = InputBox("more input")
        If farinper(a) < 0 Or farinper(a) > 1 Then
        MsgBox ("more error handle")
        GoTo 788
        End If
Next a


If Application.WorksheetFunction.Sum(farinper) < 1 Then
MsgBox ("info")
GoTo 86
End If
If Application.WorksheetFunction.Sum(farinper) > 1 Then
MsgBox ("error handle")
GoTo 13
End If

sheet1.Cells(27, 3) = farinper(0) ' PREMİX!!

a = 1

For a = 1 To 18

If a = 3 Or a = 4 Then GoTo 9424 'skip unecessary entry

sheet1.Cells(a + 24, 2) = farinper(a)

9424

Next a

1 个答案:

答案 0 :(得分:0)

我收到错误&#34;类型不匹配&#34;在您的代码的以下行

        If farin = a Then farinper(a) = InputBox("more input")

当我在InputBox中输入非数字字符时。

如果&#34; a&#34;是InputBox的输入,&#34; a&#34;不能分配给farinper()因为它们的类型是&#34; String&#34;和&#34; Double&#34;。

我猜你遇到了这个错误。

相关问题