+ Reply to Thread
Results 1 to 5 of 5

Call macro (Sheet 1) from any change in sheet 2

  1. #1
    Registered User
    Join Date
    12-12-2012
    Location
    Utrecht, Netherlands
    MS-Off Ver
    Excel 2007
    Posts
    6

    Call macro (Sheet 1) from any change in sheet 2

    Hi folks,

    I have the following target:
    I got a macro in sheet 1, which I want to trigger after a change in sheet 2.

    My idea to do this is my a sub in sheet 2:

    Private Sub Worksheet_Change(ByVal Target As Range)
    Call Markmacro
    End Sub


    Which is referring to:

    Sub Markmacro()

    Range("D3:E3").Select
    Selection.Copy
    lMaxRows = Cells(Rows.Count, "G").End(xlUp).Row
    Range("G" & lMaxRows + 1).Select
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
    :=False, Transpose:=False

    End Sub


    If I place the last sub in a module it works, only it works in sheet 2 i.s.o. sheet 1.

    Googling my issues directed me to multiple forums on this topic which offer this solution:

    Private Sub Worksheet_Change(ByVal Target As Range)
    Call Sheet1.Markmacro
    End Sub


    Somehow the sheet1. additive is not working (run-time error 1004, application defined or object defined error).

    I know my mistake is probably very stupid, which is frustrating me enormous.

    Thanks in advance for any help,

    Cheers 'n Beers - Mark

  2. #2
    Forum Expert Jakobshavn's Avatar
    Join Date
    08-17-2012
    Location
    Lakehurst, NJ, USA
    MS-Off Ver
    Excel 2007
    Posts
    1,970

    Re: Call macro (Sheet 1) from any change in sheet 2

    I would leave Markmacro in a standard module. When it is called from the Event Macro, it will attempt to do the copy/paste on the Active sheet (sheet2). If you want to do the copy/paste on sheet1, you should make that explicit within Markmacro.
    Gary's Student

  3. #3
    Registered User
    Join Date
    12-12-2012
    Location
    Utrecht, Netherlands
    MS-Off Ver
    Excel 2007
    Posts
    6

    Re: Call macro (Sheet 1) from any change in sheet 2

    HI Jakobshavn,

    Thanks for your quick reply.

    I thought of that option as well, but I fail to make that explicit.

    Might be worthwhile to mention that I am a noob in VBA.

    C&B, Mark

  4. #4
    Forum Expert Jakobshavn's Avatar
    Join Date
    08-17-2012
    Location
    Lakehurst, NJ, USA
    MS-Off Ver
    Excel 2007
    Posts
    1,970

    Re: Call macro (Sheet 1) from any change in sheet 2

    Within the Sheet2 code:

    Please Login or Register  to view this content.
    Within the standard module:

    Please Login or Register  to view this content.
    Make sure I have not "broken" the spelling of the sheet names.

  5. #5
    Registered User
    Join Date
    12-12-2012
    Location
    Utrecht, Netherlands
    MS-Off Ver
    Excel 2007
    Posts
    6

    Re: Call macro (Sheet 1) from any change in sheet 2

    Your changes in the standard code seem to work!

    What do you want to achieve with the changes in the sheet 2 code?

    Thanks mate! Much appriciated!

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1