+ Reply to Thread
Results 1 to 3 of 3

Multiple Worksheet Change Events

Hybrid View

  1. #1
    Registered User
    Join Date
    08-09-2010
    Location
    Mississippi
    MS-Off Ver
    Excel 2007
    Posts
    12

    Multiple Worksheet Change Events

    Hello All,
    I have an estimating sheet (portion attached) that I have been working on and I have hit a block. I have a worksheet change event that clears the data in cells B25:29,B32:33, and L3:21 when the option 'Standard' is selected in cell B3 from a drop down list. I used the following code to make this happen:

    Private Sub Worksheet_Change(ByVal Target As Range)
    If Target.Address = "$B$3" Then
    If Target.Value = "Standard" Then
    Range("B25:B29").Select
        Selection.ClearContents
    Range("B32:B33").Select
        Selection.ClearContents
    Range("L2:L21").Select
        Selection.ClearContents
    Range("B3").Select
    
    End If
    End If
    End Sub
    As you can see, there are three other "phases" that are just like phase 1 (directly below), where the macro runs. I want it to do the same thing in each of the other three phases, but can't seem to get it. I run into only being able to run one worksheet change event and can't figure out how to nest them. Any help would be appreciated.
    Attached Files Attached Files
    Last edited by justinharris; 03-09-2011 at 06:12 PM. Reason: put code tags on

  2. #2
    Forum Guru
    Join Date
    03-02-2006
    Location
    Los Angeles, Ca
    MS-Off Ver
    WinXP/MSO2007;Win10/MSO2016
    Posts
    12,937

    Re: Multiple Worksheet Change Events

    Private Sub Worksheet_Change(ByVal Target As Range)
    
        Select Case Target.Address(0, 0)
            Case Is = "B3"
                Select Case Target.Value
                    Case Is = "Standard"
                        Range("B25:B29, B32:B33, L2:L21").Select
                        Selection.ClearContents
                        Range("B3").Select
                    Case Is = "24 Hour"
                        'do something
                End Select 'B3
            Case Is = "Next test cell"
               ' etc
        End Select
    End Sub
    Ben Van Johnson

  3. #3
    Registered User
    Join Date
    08-09-2010
    Location
    Mississippi
    MS-Off Ver
    Excel 2007
    Posts
    12

    Re: Multiple Worksheet Change Events

    Thanks protonLeah, it seems to be working great!

+ 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