Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
233 views
in Technique[技术] by (71.8m points)

excel - Type mismatch, conflicting macros

The first VBA script I have is working fine,

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

This makes all text entered in a cell capitalize after entered by user

Then I have a macro button to clear certain cells

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

After pressing this macro it works fine, but I do get a "Run-time error '13': Type mismatch" error and the first script stops working and I have to restart the excel sheet.

How can I fix this??

The debug takes me to .Value = UCase(.Value) from the first script

thank you

question from:https://stackoverflow.com/questions/65911351/type-mismatch-conflicting-macros

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

You need to do following this code:-

Not More Issue in code simple First EnableEvents = false and before finished march write EnableEvents = true

Like this Code :

 Sub inputcaps()
   Application.EnableEvents = False

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

   Application.EnableEvents = True

End Sub


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...