类型不匹配,宏冲突

Type mismatch, conflicting macros

我的第一个 VBA 脚本工作正常,

Private Sub Worksheet_Change(ByVal Target As Range)
If Not (Application.Intersect(Target, Range("C9:G9,C15:G15,C21:G21,C27,G27")) _
  Is Nothing) Then
    With Target
        If Not .HasFormula Then
            Application.EnableEvents = False
            .Value = UCase(.Value)
            Application.EnableEvents = True
        End If
    End With
End If
End Sub

这使得在用户输入后单元格中输入的所有文本都大写

然后我有一个宏按钮来清除某些单元格

Sub inputcaps()
Range("C9", "G9").Value = ""
End Sub

按下此宏后它工作正常,但我确实收到“运行-time error '13': Type mismatch”错误并且第一个脚本停止工作,我必须重新启动 excel sheet.

我该如何解决这个问题?

调试将我从第一个脚本带到 .Value = UCase(.Value)

谢谢

您需要执行以下代码:-

不再是简单代码中的问题 首先 EnableEvents = false 并在完成 3 月之前写入 EnableEvents = true

喜欢这个代码:

 Sub inputcaps()
   Application.EnableEvents = False

    Range("C9", "G9").Value = ""

   Application.EnableEvents = True

End Sub