+ Reply to Thread
Results 1 to 10 of 10

Multiple event macros in a sheet!

Hybrid View

  1. #1
    Registered User
    Join Date
    06-02-2020
    Location
    Thailand
    MS-Off Ver
    2013
    Posts
    8

    Multiple event macros in a sheet!

    Hi all,

    I want to run multiple event macros in the same sheet but being a newbie, I can't figure out how to do it. Below are my two events.

    Private Sub Worksheet_SelectionChange(ByVal Target As Range)
        Range("A1").Value = ActiveCell.Address
    End Sub
    Private Sub Worksheet_Change(ByVal Target As Range)
    
    If Target.Row = 3 And Target.Column = 6 Then
    
    Application.EnableEvents = False
    
    Sheets("List").Range("F4").Value = [=IFERROR(VLOOKUP($F$3,Data!$A$1:$C$7,2,0),"")]
    
    Sheets("List").Range("F5").Value = [=IFERROR(VLOOKUP($F$3,Data!$A$1:$C$7,3,0),"")]
    
    
    End If
    
    Application.EnableEvents = True
    
    
    End Sub
    Thank you for your time and help.
    Last edited by itskenn1; 08-01-2021 at 02:55 AM.

  2. #2
    Forum Expert Mumps1's Avatar
    Join Date
    10-10-2012
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2010, 365
    Posts
    8,026

    Re: Multiple event macros in a sheet!

    You can run multiple event macros as long as they are not of the same type. You have one Worksheet_SelectionChange macro and one Worksheet_Change macro so that is OK.
    You can say "THANK YOU" for help received by clicking the Star symbol at the bottom left of the helper's post.
    Practice makes perfect. I'm very far from perfect so I'm still practising.

  3. #3
    Registered User
    Join Date
    06-02-2020
    Location
    Thailand
    MS-Off Ver
    2013
    Posts
    8

    Re: Multiple event macros in a sheet!

    Thanks Mumps1

    Actually that's exactly what I thought too and I tried it but it didn't work. So now I'm wondering, should I "end sub"? If not how do I make it work without "End Sub"?

  4. #4
    Forum Expert Mumps1's Avatar
    Join Date
    10-10-2012
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2010, 365
    Posts
    8,026

    Re: Multiple event macros in a sheet!

    You can't!!! It would be easier to help and test possible solutions if you could attach a copy of your file. Explain in detail what you want to do referring to specific cells, rows, columns and sheets using a few examples from your data (de-sensitized if necessary). See the yellow banner at the top of this page for instructions to attach a file.

  5. #5
    Registered User
    Join Date
    06-02-2020
    Location
    Thailand
    MS-Off Ver
    2013
    Posts
    8

    Re: Multiple event macros in a sheet!

    Thanks Mumps1 I really appreciate you taking the time. You know what, I'm using it in different sheets now. However I'll attach a copy once I have a proper structure of the file since I'm still in the process of designing.

  6. #6
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    48,102

    Re: Multiple event macros in a sheet!

    You probably just need this:

    Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    Application.EnableEvents = False
        Range("A1").Value = ActiveCell.Address
    Application.EnableEvents = True
    End Sub
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


  7. #7
    Registered User
    Join Date
    06-02-2020
    Location
    Thailand
    MS-Off Ver
    2013
    Posts
    8

    Re: Multiple event macros in a sheet!

    Hi TMS,

    Thank you so much... it worked like a charm.

  8. #8
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    48,102

    Re: Multiple event macros in a sheet!

    Should have said ... this

        Range("A1").Value = ActiveCell.Address
    will fire the Worksheet_Change event handler.

  9. #9
    Registered User
    Join Date
    06-02-2020
    Location
    Thailand
    MS-Off Ver
    2013
    Posts
    8

    Re: Multiple event macros in a sheet!

    This is what I did with TMS's suggestion.

    Private Sub Worksheet_SelectionChange(ByVal Target As Range)
        
        On Error GoTo 0
        With ActiveSheet.Shapes("PS")
        .Top = Target.Offset(0).Top
        .Left = Target.Offset(0, 1).Left
        End With
        
        Application.EnableEvents = False
        Range("F1").Value = ActiveCell.Value
    Application.EnableEvents = True
    End Sub
    As you can see these are two macro events and they are now working without any error.

    Thanks again.

  10. #10
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    48,102

    Re: Multiple event macros in a sheet!

    You're welcome.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Multiple Macros on Single Sheet
    By eeacolyte in forum Excel Programming / VBA / Macros
    Replies: 30
    Last Post: 01-05-2022, 04:43 PM
  2. Multiple macros for one work sheet
    By heggej in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 04-01-2019, 11:04 AM
  3. [SOLVED] VBA Macros single event (Enter & Exit) for multiple userform textboxes
    By hecgroups in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 01-09-2019, 12:54 PM
  4. Multiple Macros on this spread sheet ... NEED HELP!
    By potthoffw in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 08-10-2016, 11:19 AM
  5. Same VBA event multiple times in one work sheet
    By glenn0004 in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 07-28-2015, 11:37 AM
  6. [SOLVED] Simple error: List multiple sheet names in Workbook_SheetActivate event
    By onmyway in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 03-01-2015, 05:44 AM
  7. [SOLVED] Multiple Macros From Multiple Dropdown Lists on one sheet.
    By MagyarLou in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 12-29-2013, 04:33 PM

Tags for this Thread

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