View Single Post
 
Old 11-29-2018, 01:00 PM
trevorc trevorc is offline Windows 7 32bit Office 2013
Competent Performer
 
Join Date: Jan 2017
Posts: 173
trevorc will become famous soon enoughtrevorc will become famous soon enough
Default

I have my code working ok now, the issue I had was that any code that changed/added data to cells was bringing up the error - Code execution was interrupted. I found this online Application.EnableCancelKey = xlDisabled to stop that happening, but have to place it in all macros that cause the error. is there a way to do this only once in the project only?

Code:
Private Sub Add_customer_data()
Application.EnableCancelKey = xlDisabled
Dim customer_name
customer_name = ActiveCell.Value
With Sheets("Customer").Range("H4:H" & ActiveCell.Row - 1)
    Set C = .Find(customer_name, LookIn:=xlValues)
    If Not C Is Nothing Then
    t = C.Row
    ttt = ActiveCell.Row
    Application.EnableEvents = False
    Sheets("Customer").Range("H" & ttt).Select
    Sheets("Customer").Range("I" & t & ":L" & t).Copy
    Range("I" & ttt).PasteSpecial Paste:=xlPasteValues
    Application.CutCopyMode = False
    Sheets("Customer").Range("Y" & t & ":AH" & t).Copy
    Sheets("Customer").Range("Y" & ttt).Select
    Range("Y" & ttt).PasteSpecial Paste:=xlPasteValues
    Application.CutCopyMode = False
    Sheets("Customer").Range("H" & ttt).Select
    End If
End With
End Sub
Reply With Quote