2016-07-21 113 views
0

不幸的是,我的collaegue目前正在度假,我坐在这里与他的VBA代码,我总是触发运行时13错误。任何帮助?错误代码标有**Excel VBA运行时错误类型不匹配13

Function checkForMapping(sheetName As String, checkColumn As Integer, displayColumn As Integer, firstRow As Integer, text As String) As Boolean 

Worksheets(sheetName).Activate 

Dim lastRow As Long 
lastRow = ActiveSheet.Cells(Rows.Count, 1).End(xlUp).Row 

Dim values As String 
Dim currentRow As Long 
Dim currentValue As String 


For currentRow = firstRow To lastRow Step 1 
    **If Not Round(Cells(currentRow, checkColumn), 1) = Round(1, 10) Then** 
     currentValue = Cells(currentRow, displayColumn) 
     If Not InStr(values, currentValue) > 0 Then 
      If Len(values) > 0 Then 
       values = values & ", " 
      End If 
      values = values & currentValue 
     End If 
    End If 
Next 

checkForMapping = (Len(values) > 0) 

If checkForMapping Then 
    result = MsgBox(text & " " & values, (vbOKOnly + vbInformation), "Info") 
End If 

感谢您的帮助!

+0

你从哪里得到错误?告诉我们在发生错误时突出显示哪一行 – Dave

+1

@Dave他在行上放了一个** –

+0

该错误消息通常意味着数据类型不匹配,放置断点或应用程序中断时,通过它,你会看到错误在哪里...... –

回答

0

也许你可以前添加以下行:

If Not IsError(Cells(currentrow, checkcolumn)) Then

,然后记得使用粘在另一

End If

+0

谢谢!它正在工作!你们真棒! – Sven

+0

不用担心,完全取决于你,没有任何压力,但是因为你是新手,所以你可能希望标记一个答案,如果它给了你你所需要的。 [This](http://stackoverflow.com/help/someone-answers)会进一步解释。 –

0

如果什么:

If Left(Cells(currentRow, checkColumn).Value2, 1) <> "1" Then 
相关问题