2016-03-03 43 views
0

我想指定一個單元格範圍來顯示#N/A如果字符結果沒有顯示,另一個單元格範圍顯示#DIV/0!如果數字結果沒有顯示。下面是導致我收到「類型不匹配」錯誤的代碼。我應該如何編輯?爲什麼我收到此類代碼的'類型不匹配錯誤'?

Sub novalue() 

    Dim x As Integer 

    For x = 2 To 100 

    If Cells(x, 7).Value = 0 Then 
    Cells(x, 7).Value = "#N/A" 

    ElseIf Cells(x, 8).Value = 0 Then 
    Cells(x, 8).Value = "#N/A" 

    End If 

Next x 
End Sub 
+0

您變量對象進行比較的字符串。這是類型不匹配的根源 – Charmi

回答

0

試試這個代碼,請:

Sub novalue() 
For Each cell In Range("A1:C100") 
    If cell.Value = "" Then 
     cell.Value = "#N/A" 
    End If 
Next cell 
For Each cell In Range("D1:BV100") 
    If cell.Value = "" Then 
     cell.Value = "#DIV/0!" 
    End If 
Next cell 
End Sub 
相關問題