2014-01-21 116 views
0

下面的代碼完美地工作2003的excel下,但在2010年返回錯誤 '類型不匹配13' 在以下行 「如果ARRAY2(1,i)的<> 0,則」類型不匹配13 2010

任何有什麼想法如何解決這個問題?

提前THX

桑尼

她是代碼:

Sub BerekenGepresteerdeUrenVoorEenMaand(SheetNaam As String) 

Application.ScreenUpdating = False 
Application.DisplayAlerts = False 

Dim Array1 As Variant 
Dim Array2 As Variant 

Dim Range1 As Range 
Dim Range2 As Range 
Dim RangeTarget1 As Range 
Dim RangeTarget2 As Range 
Dim mRange As Excel.Range 
Dim RangeNieuwSaldo As Range 

Dim i As Integer 
Dim j As Integer 
Dim k As Integer 
Dim l As Integer 

Dim subTotaal As Double 

ActiveWorkbook.Worksheets(SheetNaam).Activate 

Set Range1 = ActiveSheet.Range("EersteRij") 
Set Range2 = ActiveSheet.Range("LaatsteRij") 
Set RangeTarget1 = ActiveSheet.Range("NaamVeld") 
Set RangeTarget2 = ActiveSheet.Range("SaldiVeld") 

Array1 = Range1.Value 
Array2 = Range2.Value 

RangeTarget1.Locked = False 
RangeTarget2.Locked = False 

j = 0 
For i = LBound(Array1, 2) To UBound(Array1, 2) 

If Array2(1, i) <> 0 Then 'Line generating error 

j = j + 1 

RangeTarget1.Cells(j, 1).Value = Array1(1, i) 
RangeTarget2.Cells(j, 1).Value = Array2(1, i) 

Else 

End If 

Next 

For k = j + 1 To 11 

RangeTarget1.Cells(k, 1).Value = "" 
RangeTarget2.Cells(k, 1).Value = "" 

Next 

RangeTarget1.Locked = False 
RangeTarget2.Locked = False 

Erase Array1 
Erase Array2 

Set Range1 = Nothing 
Set Range2 = Nothing 
Set RangeTarget1 = Nothing 
Set RangeTarget2 = Nothing 

Application.EnableEvents = True 
Application.ScreenUpdating = True 
Application.DisplayAlerts = True 


End Sub 
+1

變化'暗淡我作爲Interger'到'暗淡我作爲Integer' –

+0

對不起,這是錄入錯誤複製代碼論壇 – user3220149

+0

數組2 = Range2.Value時,確保區域2的東西@ user3220149 – Stephenloky

回答

0

我想,在某些時候,我變得比數組2輸入數據... 一樣,沒有大數據存儲在array2(1,10000)左右,沒有什麼不是數字(如<> 0) 所以也許你需要在出現故障線路之前的故障保護條件:

if not array2(1,i) is nothing then 'or you might just want to exit the For loop here. 
    if array2(1,i)<>0 then ... 
'if this doesn't work try if not IsEmpty(array2(1,i)) as condition 

嘗試,沒有在這裏seing實際的數據我不能告訴更多...

閱讀更多關於UBOUND也許是太,這是你的陣列的上限,是在它或沒有數據。 我曾經想過,它是我數組中最後一項數據,但事實上並不是這樣。

dim test(20) as integer 
test(1)=23 
.. 
test(10)=44 'last input 
a=ubound(test) 'my guess it will return 20, and not 10 
+0

確定答覆。 我發現Array2中的數據存在問題:它包含一些生成類型不匹配錯誤的錯誤值。 問題解決! – user3220149