2014-10-17 71 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