+ Reply to Thread
Results 1 to 7 of 7

Event Macro

  1. #1
    Registered User
    Join Date
    04-01-2005
    Posts
    19

    Event Macro

    Dear all,

    I've got a spreadsheet that produces summary information based upon a table that is updated weekly by a supplier, and then copy and pasted into the summary spreadsheet.
    I would like to run a macro that I currently have assigned to a button on one of the sheets automatically when the data table from the supplier is updated. Thus removing the need for the user to click the button everytime the information (and subsequently the report it generates) is updated.

    How do I do this? I think I need some code somewhere, but I'm a bit of a code novice!

    Thanks,

    Steve

  2. #2
    Forum Contributor
    Join Date
    06-10-2004
    Location
    India
    Posts
    1,066
    How is the tables updated every week.

    Mangesh

  3. #3
    Registered User
    Join Date
    04-01-2005
    Posts
    19
    The supplier has a template sheet that is updated, and then copy and pasted into a data sheet within my summary workbook.

  4. #4
    Bill Martin -- (Remove NOSPAM from address)
    Guest

    Re: Event Macro

    stevepain wrote:
    > Dear all,
    >
    > I've got a spreadsheet that produces summary information based upon a
    > table that is updated weekly by a supplier, and then copy and pasted
    > into the summary spreadsheet.
    > I would like to run a macro that I currently have assigned to a button
    > on one of the sheets automatically when the data table from the
    > supplier is updated. Thus removing the need for the user to click the
    > button everytime the information (and subsequently the report it
    > generates) is updated.
    >
    > How do I do this? I think I need some code somewhere, but I'm a bit of
    > a code novice!
    >
    > Thanks,
    >
    > Steve
    >
    >



    Here's a snippet of code demonstrating what you want I believe:

    Private Sub worksheet_change(ByVal Target As Excel.range)
    MsgBox "Cell Changed"
    End Sub

    You need to place this not in the "Modules" as you normally do, but the
    "Microsoft Excel Objects" for the specific sheet you want to monitor for changes.

    Good luck...

    Bill

  5. #5
    Bill Martin -- (Remove NOSPAM from address)
    Guest

    Re: Event Macro

    stevepain wrote:
    > Dear all,
    >
    > I've got a spreadsheet that produces summary information based upon a
    > table that is updated weekly by a supplier, and then copy and pasted
    > into the summary spreadsheet.
    > I would like to run a macro that I currently have assigned to a button
    > on one of the sheets automatically when the data table from the
    > supplier is updated. Thus removing the need for the user to click the
    > button everytime the information (and subsequently the report it
    > generates) is updated.
    >
    > How do I do this? I think I need some code somewhere, but I'm a bit of
    > a code novice!
    >
    > Thanks,
    >
    > Steve
    >
    >



    Here's a snippet of code demonstrating what you want I believe:

    Private Sub worksheet_change(ByVal Target As Excel.range)
    Dim ChangeRange As range
    Application.EnableEvents = False
    Set ChangeRange = range("A1:B2")
    If Not Intersect(Target, ChangeRange) Is Nothing Then
    MsgBox "Cell within range has changed"
    End If
    Application.EnableEvents = True
    End Sub

    You need to place this not in the macro "Modules" as you normally do, but the
    "Microsoft Excel Objects" for the specific sheet you want to monitor for
    changes. If anything is changed in the range A1:B2 on that sheet, then the code
    inside the If/EndIf block will execute.

    Good luck...

    Bill

  6. #6
    Forum Contributor
    Join Date
    06-10-2004
    Location
    India
    Posts
    1,066
    Then maybe you can call that macro (attached to the button) at workbook_close event.

    This event goes in the This_Workbook module. You will have to take care that if you open the book sometime when you are not updating, even then this will be fired.


    Mangesh

  7. #7
    Mangesh Yadav
    Guest

    Re: Event Macro

    Hi Bill / Stevepain

    You have to be careful, as for every change in the cell value, your "button
    macro" will be triggered when you use the Change event.

    MAngesh




    "Bill Martin -- (Remove NOSPAM from address)" <[email protected]>
    wrote in message news:Orgo#[email protected]...
    > stevepain wrote:
    > > Dear all,
    > >
    > > I've got a spreadsheet that produces summary information based upon a
    > > table that is updated weekly by a supplier, and then copy and pasted
    > > into the summary spreadsheet.
    > > I would like to run a macro that I currently have assigned to a button
    > > on one of the sheets automatically when the data table from the
    > > supplier is updated. Thus removing the need for the user to click the
    > > button everytime the information (and subsequently the report it
    > > generates) is updated.
    > >
    > > How do I do this? I think I need some code somewhere, but I'm a bit of
    > > a code novice!
    > >
    > > Thanks,
    > >
    > > Steve
    > >
    > >

    >
    >
    > Here's a snippet of code demonstrating what you want I believe:
    >
    > Private Sub worksheet_change(ByVal Target As Excel.range)
    > Dim ChangeRange As range
    > Application.EnableEvents = False
    > Set ChangeRange = range("A1:B2")
    > If Not Intersect(Target, ChangeRange) Is Nothing Then
    > MsgBox "Cell within range has changed"
    > End If
    > Application.EnableEvents = True
    > End Sub
    >
    > You need to place this not in the macro "Modules" as you normally do, but

    the
    > "Microsoft Excel Objects" for the specific sheet you want to monitor for
    > changes. If anything is changed in the range A1:B2 on that sheet, then

    the code
    > inside the If/EndIf block will execute.
    >
    > Good luck...
    >
    > Bill




+ 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