ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Worksheet Functions (https://www.excelbanter.com/excel-worksheet-functions/)
-   -   run macro after paste (https://www.excelbanter.com/excel-worksheet-functions/207958-run-macro-after-paste.html)

K

run macro after paste
 
Is it possible to run a macro after pasting some data onto a worksheet

Dave Peterson

run macro after paste
 
Sure.

Just alt-f8, select the macro and click run.

If you mean you want to run a macro automatically after pasting, then probably
not.

Excel can run a _change event when a range changes, but it doesn't know if that
range changed because of the user typing or because of a paste.

K wrote:

Is it possible to run a macro after pasting some data onto a worksheet


--

Dave Peterson

Gord Dibben

run macro after paste
 
It is possible using event code but "some data" needs clarifying.

Copying just data or formulas?

Pasting into one cell or a range of cells?

If a range of cells what would it be?

Variable or fixed range?

Code for one cell if not pasting a formula...................

Private Sub Worksheet_Change(ByVal Target As Excel.Range)
On Error GoTo stoppit
Application.EnableEvents = False
If Target.Address = "$A$2" And Not Target.HasFormula Then
MsgBox "a change has been made to A2"
'Call Macroname
End If
Application.CutCopyMode = False
stoppit:
Application.EnableEvents = True
End Sub


Gord Dibben MS Excel MVP

On Mon, 27 Oct 2008 12:28:01 -0700, K wrote:

Is it possible to run a macro after pasting some data onto a worksheet



K

run macro after paste
 
Yes copying data from word - basically the sheet is protected to protect the
formulas, this is because the sheet is used by many users , the problem being
that when the word report (which has been exported from aanother program) is
pasted its propertys are locked therefore next time someone comes to use it
then the cells they need to delete & paste the new data in are protected.
Now I have my Formular to unprotect, unlock & re protect the cells but I
would like this to trigger automatically from the paste. At the moment it
triggers everytime someone clicks on the particular sheet which is OK but
not Ideal

"Gord Dibben" wrote:

It is possible using event code but "some data" needs clarifying.

Copying just data or formulas?

Pasting into one cell or a range of cells?

If a range of cells what would it be?

Variable or fixed range?

Code for one cell if not pasting a formula...................

Private Sub Worksheet_Change(ByVal Target As Excel.Range)
On Error GoTo stoppit
Application.EnableEvents = False
If Target.Address = "$A$2" And Not Target.HasFormula Then
MsgBox "a change has been made to A2"
'Call Macroname
End If
Application.CutCopyMode = False
stoppit:
Application.EnableEvents = True
End Sub


Gord Dibben MS Excel MVP

On Mon, 27 Oct 2008 12:28:01 -0700, K wrote:

Is it possible to run a macro after pasting some data onto a worksheet





All times are GMT +1. The time now is 04:08 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com