[英]Excel macro - type mismatch error
我是菜鳥
當單元格值更改為“已關閉”時,我的宏會添加一個日期。 具體來說,當M列中的單元格值更改為“已關閉”時,它將在K列的左側向左添加日期2個單元格。工作正常,直到我在任一列中編輯了多個單元格 。 如果我這樣做,我會得到13型不匹配錯誤。
這很糟糕,因為這意味着每次我自動填充時都會出現錯誤。
提前致謝。
Option Explicit
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Column = 13 And Target = "Closed" Then
Target.Offset(0, -2) = Format(Now(), "yyyy-mm-dd")
End If
End Sub
嘗試這個:
Private Sub Worksheet_Change(ByVal Target As Range)
Dim cell As Range
For Each cell In Target
If cell.Column = 13 And cell = "Closed" Then
Target.Offset(0, -2) = Format(Now(), "yyyy-mm-dd")
End If
Next cell
End Sub
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.