[英]Run-time error '13': Type mismatch error code
我正在使用以下代碼創建一個數據列,我可以將其用作數據透視表中的過濾器。
代碼工作,但它標記“運行時錯誤'13':類型不匹配”代碼錯誤。 任何人都可以幫助我更改代碼以消除錯誤消息。
這是我正在使用的代碼。
Sub negativepivot()
Sheets("owssvr").Select
Columns("W:W").Select
Selection.ClearContents
Range("W2").Select
ActiveCell.FormulaR1C1 = "=Table_owssvr[@[Count Zero]]"
Range("W2").Select
Selection.AutoFill Destination:=Range("W2:W230"), Type:=xlFillDefault
Range("W2:W230").Select
ActiveWindow.SmallScroll Down:=-230
Range("W1").Select
ActiveCell.FormulaR1C1 = "Negative results"
For Each Cell In Range("W2:W230")
If Cell.Value <= 0 Then
Cell.Value = "Negative"
Else
Cell.Value = Cell.Value
End If
Next
End Sub
避免使用.Select
或.Activate
盡可能。 檢查這個和這個其他方法和原因。 此外,在前一個鏈接中,檢查With
的用法。
您的代碼在編程上看起來是正確的,因此請嘗試改進整體樣式。 VBA在某種程度上很敏感。
Sub NegativePivotMod()
With Sheets("owssvr")
.Range("W:W").ClearContents
With .Range("W2")
.FormulaR1C1 = "=Table_owssvr[@[Count Zero]]"
.AutoFill Destination:=.Range("W2:W230"), Type:=xlFillDefault
End With
Range("W1").FormulaR1C1 = "Negative results"
For Each Cell In .Range("W2:W230")
If Cell.Value < 0 Then
Cell.Value = "Negative"
End If
Next
End With
End Sub
如果這有幫助,請告訴我們。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.