+ Reply to Thread
Results 1 to 4 of 4

Run a macro when a change occurs in a range of cells (two macros and two cell ranges)

Hybrid View

  1. #1
    Registered User
    Join Date
    02-02-2014
    Location
    London
    MS-Off Ver
    Excel 2016
    Posts
    37

    Run a macro when a change occurs in a range of cells (two macros and two cell ranges)

    I'm using this code to run a macro whenever data is entered/removed from a cell within a range.

    Private Sub Worksheet_Change(ByVal Target As Range)
    
    Dim KeyCells As Range
    
    Set KeyCells = Range("M3:M52")
    
    If Not Application.Intersect(KeyCells, Range(Target.Address)) _
        Is Nothing Then
        
    Call FormatChart
    
    End If
    End Sub
    Now I need to do the same thing for a different cell range (E3:E52) and a different macro (FormatChart2). Do I need to make a new Private sub or can I add it into the existing code?
    Last edited by zanguard80; 02-03-2014 at 07:12 AM.

  2. #2
    Forum Expert
    Join Date
    01-23-2013
    Location
    USA
    MS-Off Ver
    Microsoft 365 aka Office 365
    Posts
    3,863

    Re: Run a macro when a change occurs in a range of cells (two macros and two cell ranges)

    Hi,

    If Not Application.Intersect(KeyCells, Range(Target.Address))  Is Nothing Then
        
      Call FormatChart
    
    Else If Not Application.Intersect(KeyCells2, Range(Target.Address))  Is Nothing Then
        
      Call FormatChart2
    
    End If
    Lewis

  3. #3
    Forum Guru :) Sixthsense :)'s Avatar
    Join Date
    01-01-2012
    Location
    India>Tamilnadu>Chennai
    MS-Off Ver
    2003 To 2010
    Posts
    12,788

    Re: Run a macro when a change occurs in a range of cells (two macros and two cell ranges)

    Replace this....

    Private Sub Worksheet_Change(ByVal Target As Range)
    Dim KeyCells As Range
    
    Set KeyCells = Range("M3:M52")
    
    If Not Application.Intersect(KeyCells, Range(Target.Address)) Is Nothing Then
        Call FormatChart
    End If
    
    Set KeyCells = Range("E3:E52")
    
    If Not Application.Intersect(KeyCells, Range(Target.Address)) Is Nothing Then
        Call FormatChart2
    End If
    
    End Sub


    If your problem is solved, then please mark the thread as SOLVED>>Above your first post>>Thread Tools>>
    Mark your thread as Solved


    If the suggestion helps you, then Click *below to Add Reputation

  4. #4
    Registered User
    Join Date
    02-02-2014
    Location
    London
    MS-Off Ver
    Excel 2016
    Posts
    37

    Re: Run a macro when a change occurs in a range of cells (two macros and two cell ranges)

    Thanks.

+ 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. [SOLVED] ? Variable Ranges ? how to change address in Formula range base on another cell value ?
    By DrAlloway in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 01-27-2014, 07:34 PM
  2. Change range of cells within VBA macro and copy and paste to fixed cell range
    By Mannyny in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 07-20-2012, 11:51 AM
  3. [SOLVED] macros to change fonts in range depending on cell value
    By vash1628 in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 05-28-2012, 03:51 PM
  4. Insert row after date change
    By nana15nuna in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 01-24-2012, 11:43 PM
  5. conditional cell shading when a change occurs
    By zooeyhall in forum Excel General
    Replies: 1
    Last Post: 06-06-2005, 01:05 PM

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