+ Reply to Thread
Results 1 to 5 of 5

2 Worksheet "Change" Proceedure on one sheet?

Hybrid View

realniceguy5000 2 Worksheet "Change"... 04-16-2009, 02:58 PM
GuruWannaB Re: 2 Worksheet "Change"... 04-16-2009, 03:08 PM
VBA Noob Re: 2 Worksheet "Change"... 04-16-2009, 03:32 PM
realniceguy5000 Re: 2 Worksheet "Change"... 04-16-2009, 03:36 PM
realniceguy5000 Re: 2 Worksheet "Change"... 04-16-2009, 03:33 PM
  1. #1
    Valued Forum Contributor realniceguy5000's Avatar
    Join Date
    03-20-2008
    Location
    Fl
    MS-Off Ver
    Excel 2003 & 2010
    Posts
    951

    2 Worksheet "Change" Proceedure on one sheet?

    How can I have 2 worksheet proccedures on the same sheet?

    Is it possible? How to make it happen?

    Thanks so much!!! Mike

    Here is my codes:
    #1
    Private Sub Worksheet_Change(ByVal Target As Range)
    
        If Target.Cells.Count > 1 Then
            Exit Sub
        End If
        On Error GoTo ErrHandler:
        If Not Application.Intersect(Me.Range("A5:B1200"), Target) Is Nothing Then
            If IsNumeric(Target.Value) = False Then
                Application.EnableEvents = False
                            Target.Value = StrConv(Target.Text, vbProperCase)
                Application.EnableEvents = True
            End If
        End If
    ErrHandler:
        Application.EnableEvents = True
    End Sub
    #2
    Private Sub Worksheet_Change(ByVal Target As Range)
        
                    Set MyPlage = Range("M5:M1200")
        For Each Cell In MyPlage
        
            If Cell.Value = "Monday" Then
                Cell.Interior.ColorIndex = 45
            End If
            If Cell.Value = "Tuesday" Then
                Cell.Interior.ColorIndex = 4
            End If
            If Cell.Value = "Wednesday" Then
                Cell.Interior.ColorIndex = 18
            End If
            If Cell.Value = "Thursday" Then
                Cell.Interior.ColorIndex = 6
                          
            End If
            If Cell.Value = "Friday" Then
                Cell.Interior.ColorIndex = 12
            End If
            
            If Cell.Value = "Saturday" Then
                Cell.Interior.ColorIndex = 18
            End If
            
            If Cell.Value = "Sunday" Then
                Cell.Interior.ColorIndex = 22
            End If
                     
        Next
           
        End Sub
    Last edited by realniceguy5000; 04-16-2009 at 03:37 PM.

  2. #2
    Forum Contributor GuruWannaB's Avatar
    Join Date
    01-24-2008
    Location
    An hour due East of Cowtown Ohio
    MS-Off Ver
    2010
    Posts
    421

    Re: 2 Worksheet "Change" Proceedure on one sheet?

    Pick an order...have be a subroutine that is called by the other.
    I help because of the Pavlovian dog that resides in the inner me...so if you are happy with the results, please add to my reputation. It helps keep me motivated!



    Please mark your threads as Solved once it is solved. Check the FAQ's to see how.

  3. #3
    Forum Contributor VBA Noob's Avatar
    Join Date
    04-25-2006
    Location
    London, England
    MS-Off Ver
    xl03 & xl 07(Jan 09)
    Posts
    11,988

    Re: 2 Worksheet "Change" Proceedure on one sheet?

    Maybe

    Option Explicit
    Private Sub Worksheet_Change(ByVal Target As Range)
    Dim Cl As Range
    Dim i As Long
    Application.EnableEvents = False
    Select Case Target.Address(0, 0)
        Case "M5:M1200": GoTo Rng1
        Case "A5:B1200": GoTo Rng2
        '
        End Select
        
    Rng1:
        For Each Cl In Range("M5:M1200")
            If Not IsEmpty(Cl) Then
                 Select Case LCase(Cl)
                     Case "monday": i = 45
                     Case "tuesday": i = 4
                     Case "wednesday": i = 18
                     Case "thursday": i = 6
                     Case "friday": i = 12
                     Case "saturday": i = 18
                     Case "sunday": i = 22
                     Case Else: i = 0
                End Select
            End If
             Cl.Interior.ColorIndex = i
             i = 0
        Next Cl
    Rng2:
    If Target.Cells.Count > 1 Then
            Exit Sub
        End If
        On Error GoTo ErrHandler:
        If Not Application.Intersect(Me.Range("A5:B1200"), Target) Is Nothing Then
            If IsNumeric(Target.Value) = False Then
                Application.EnableEvents = False
                            Target.Value = StrConv(Target.Text, vbProperCase)
                Application.EnableEvents = True
            End If
        End If
        
    ErrHandler:
        Application.EnableEvents = True
    End Sub
    VBA Noob
    _________________________________________


    Credo Elvem ipsum etian vivere
    _________________________________________
    A message for cross posters

    Please remember to wrap code.

    Forum Rules

    Please add to your signature if you found this link helpful. Excel links !!!

  4. #4
    Valued Forum Contributor realniceguy5000's Avatar
    Join Date
    03-20-2008
    Location
    Fl
    MS-Off Ver
    Excel 2003 & 2010
    Posts
    951

    Re: 2 Worksheet "Change" Proceedure on one sheet?

    Quote Originally Posted by VBA Noob View Post
    Maybe

    Option Explicit
    Private Sub Worksheet_Change(ByVal Target As Range)
    Dim Cl As Range
    Dim i As Long
    Application.EnableEvents = False
    Select Case Target.Address(0, 0)
        Case "M5:M1200": GoTo Rng1
        Case "A5:B1200": GoTo Rng2
        '
        End Select
        
    Rng1:
        For Each Cl In Range("M5:M1200")
            If Not IsEmpty(Cl) Then
                 Select Case LCase(Cl)
                     Case "monday": i = 45
                     Case "tuesday": i = 4
                     Case "wednesday": i = 18
                     Case "thursday": i = 6
                     Case "friday": i = 12
                     Case "saturday": i = 18
                     Case "sunday": i = 22
                     Case Else: i = 0
                End Select
            End If
             Cl.Interior.ColorIndex = i
             i = 0
        Next Cl
    Rng2:
    If Target.Cells.Count > 1 Then
            Exit Sub
        End If
        On Error GoTo ErrHandler:
        If Not Application.Intersect(Me.Range("A5:B1200"), Target) Is Nothing Then
            If IsNumeric(Target.Value) = False Then
                Application.EnableEvents = False
                            Target.Value = StrConv(Target.Text, vbProperCase)
                Application.EnableEvents = True
            End If
        End If
        
    ErrHandler:
        Application.EnableEvents = True
    End Sub
    VBA Noob
    That is fantastic work... I never would have come up with this... Thank You for your guidance.... Mike

  5. #5
    Valued Forum Contributor realniceguy5000's Avatar
    Join Date
    03-20-2008
    Location
    Fl
    MS-Off Ver
    Excel 2003 & 2010
    Posts
    951

    Re: 2 Worksheet "Change" Proceedure on one sheet?

    Quote Originally Posted by GuruWannaB View Post
    Pick an order...have be a subroutine that is called by the other.
    Hmmmm, Seems simple now. It appears to be working correctly.

    Thanks for your help...

    Mike

+ 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