2014-03-26 73 views
0

我不斷收到一個運行錯誤類型13 - 類型不匹配運行錯誤類型13 - 類型不匹配

以下行:

Set cel = wshS.Columns(1).Find(What:="EMEA\" + wshT.Cells(r, 10 + cCtr).Value, _ 
    LookAt:=xlWhole, MatchCase:=False) 

你知道可能會造成什麼呢?這是什麼意思?

下面

全碼:

Sub VDA_Update() 

Dim wshT As Worksheet 
    Dim wbk As Workbook 
    Dim wshS As Worksheet 
    Dim r As Long 
    Dim m As Long 
    Dim cel As Range 
    Application.ScreenUpdating = False 
    Set wshT = ThisWorkbook.Worksheets("Master") 
    On Error Resume Next 

    ' Check whether vda.xlsx is already open 
    Set wbk = Workbooks("vda.xlsx") 
     On Error GoTo 0 
     If wbk Is Nothing Then 
     ' If not, open it 
     Set wbk = Workbooks.Open("C:\Working\vda.xlsx") 
    End If 

    ' Set worksheet on vda.xlsx 
    Set wshS = wbk.Worksheets("pc_list") 
    m = wshT.Cells(wshT.Rows.Count, 1).End(xlUp).Row 

    ' Loop though cells in column J on main.xlsm 
    For r = 1 To m 

     For cCtr = 0 To 2 

     ' Can we find the value in column A of vda.xlsx? 
     Set cel = wshS.Columns(1).Find(What:="EMEA\" + wshT.Cells(r, 10 + cCtr).Value, _ 
     LookAt:=xlWhole, MatchCase:=False) 

     If Not cel Is Nothing Then 

      ' If we find a match, then change cell color 

      If cel.Offset(0, 1).Value = "True" Then 
       wshT.Cells(r, 10 + cCtr).Interior.ColorIndex = 6 
       wshT.Cells(r, 43).Value = "Assigned" 
      ElseIf cel.Offset(0, 1).Value = "False" Then 
       wshT.Cells(r, 10 + cCtr).Interior.ColorIndex = 8 
       wshT.Cells(r, 43).Value = "Unassigned" 
      End If 

      ' If so, enter "Yes" in column M - Comms Sent? 
       ' If wshT.Cells(r, 13).Value = "" Then wshT.Cells(r, 13).Value = "Yes" 
      ' Enter "Yes" in column O - VDA Deployed? 
       If wshT.Cells(r, 15).Value = "" Then wshT.Cells(r, 15).Value = "Yes" 
      ' Enter "5.6.200" in column P - VDA Version 
       If wshT.Cells(r, 16).Value = "" Then wshT.Cells(r, 16).Value = "5.6.200" 
      ' Enter date in column Q - Migration Date 
       ' If wshT.Cells(r, 17).Value = "02/01/2014" Then wshT.Cells(r, 17).Value = "03/03/2014" 

      End If 
     Next 
    Next r 

    Application.ScreenUpdating = True 

End Sub 
+1

檢查您的單元格wshT.Cells(r,10 + cCtr).Value'是否存在表格中的任何錯誤,例如'#N/A','#VALUE!','#DIV/0!'等 –

+3

嘗試用**「EMEA \」和wshT.Cells(r,10 + cCtr)替換**「EMEA \」+ wshT.Cells(r,10 + cCtr).Value ** .Text ** –

回答

1

使用符號(&)代替What:=段之間的加號(+),你是串聯:

Set cel = wshS.Columns(1).Find(What:="EMEA\" & wshT.Cells(r, 10 + cCtr).Value, _ 
     LookAt:=xlWhole, MatchCase:=False) 

如果有一個單元價值在您的搜索範圍wshT.Cells(r, 10 + cCtr)與一個純數值,VBA將嘗試添加數字「EMEA \」數字(而不是連接它)。在這種情況下,類型不匹配將是文本和數字數據類型之一。