2014-10-17 34 views
-1

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

我认为我的问题在这里既不是,它看起来很简单,让我生病,看不到它仍然。

我的尝试:

二手application.inputbox法,宣布说,变量为整数,变型,而不是双,完全ommitted 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 
+0

是否在'vbNewLine'之后缺少'&'? 'farin = InputBox(“0 - PREMIX”&vbNewLine&“1 - etc”)'你的dd = vbNo Then GoTo 789'但标签实际上是'788'? – 2014-10-17 07:17:59

+0

不,我只是在删除^^只是编辑帖子 – user3146025 2014-10-17 07:19:11

+0

好吧,你能编辑你的问题,并更新代码? – 2014-10-17 07:19:59

回答

0

我得到一个错误“类型不匹配”在下面的一行代码

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

,当我进入了的InputBox非数字字符。

如果InputBox的“a”被输入,则“a”不能分配给farinper(),因为它们的类型是“String”和“Double”。

我想你会遇到这个错误。

+0

不,它不是输入。它只是一个整数计数器。我可能已经省略了代码的其余部分。我现在会尝试粘贴的版本。 – user3146025 2014-10-17 07:37:31

+0

哇,我刚刚意识到。该行不会给新创建的工作簿带来类型不匹配。它只在工作簿上给出它。我勒个去。 – user3146025 2014-10-17 07:41:09