+ Reply to Thread
Results 1 to 10 of 10

How to have 2 Private Sub Worksheet_Changes

Hybrid View

  1. #1
    Registered User
    Join Date
    12-15-2011
    Location
    Dallas texas
    MS-Off Ver
    Excel 2010
    Posts
    45

    How to have 2 Private Sub Worksheet_Changes

    HI currently have this code in my sheet, and would like to incorporate the second code into the same sheet.

    When I just put them together neither will work.

    Just not sure how to do it


    Code 1
    Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    
    With thisworkbook.Names("ActiveRow")
    .Name = "ActiveRow"
    .RefersToR1C1 = "=" & ActiveCell.Row
    End With
    
    End Sub
    Code 2
    Private Sub Worksheet_SelectionChange(ByVal Target As Range)
        
        'another method is to have it show if a cell that is formatted as a date is selected...see below
        If Target.NumberFormat = "m/d/yy;@" Then
            CalendarFrm.Show
        End If
          
        'another method is using Select Case...see below
        Select Case Target.NumberFormat
            Case Is = "m/d/yy", "m/d/yyyy", "m/d/yy", "mm/dd/yy", "yyyy-mmm-dd", "dd-mmm-yy"
            CalendarFrm.Show
            'Case Else
            '    MsgBox "Not a valid date format!"
        End Select
    End Sub

  2. #2
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259

    Re: How to have 2 Private Sub Worksheet_Changes

    Hello mmctague ,

    I understand the second event macro but I don't follow the purpose of the first one. Can you explain a little more about what you want to achieve?
    Sincerely,
    Leith Ross

    Remember To Do the Following....

    1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.
    2. Thank those who have helped you by clicking the Star below the post.
    3. Please mark your post [SOLVED] if it has been answered satisfactorily.


    Old Scottish Proverb...
    Luathaid gu deanamh maille! (Rushing causes delays!)

  3. #3
    Registered User
    Join Date
    06-19-2012
    Location
    Canada Eh
    MS-Off Ver
    Excel 2003, 2007, 2010
    Posts
    40

    Re: How to have 2 Private Sub Worksheet_Changes

    When you put them together, did it look like:
    Private Sub Worksheet_SelectionChange(ByVal Target As Range)
        
        'another method is to have it show if a cell that is formatted as a date is selected...see below
        If Target.NumberFormat = "m/d/yy;@" Then
            CalendarFrm.Show
        End If
          
        'another method is using Select Case...see below
        Select Case Target.NumberFormat
            Case Is = "m/d/yy", "m/d/yyyy", "m/d/yy", "mm/dd/yy", "yyyy-mmm-dd", "dd-mmm-yy"
            CalendarFrm.Show
            'Case Else
            '    MsgBox "Not a valid date format!"
        End Select
        
        With ThisWorkbook.Names("ActiveRow")
            .Name = "ActiveRow"
            .RefersToR1C1 = "=" & ActiveCell.Row
        End With
    
    
    End Sub
    It is hard to test this as none of us have the form to show but if you upload a workbook with non-sensitive data in it you may get the answer you need.
    EF killed Mordred

    46 & 2 is just ahead of me!

  4. #4
    Registered User
    Join Date
    12-15-2011
    Location
    Dallas texas
    MS-Off Ver
    Excel 2010
    Posts
    45

    Re: How to have 2 Private Sub Worksheet_Changes

    The First code highlights the entire row that has the active cell.

    The second code (when the cell is selected) will pull up a calendar that a date can be selected and then added to that cell.

    I want to make both work

  5. #5
    Registered User
    Join Date
    12-15-2011
    Location
    Dallas texas
    MS-Off Ver
    Excel 2010
    Posts
    45

    Re: How to have 2 Private Sub Worksheet_Changes

    Is there a way to make it onl look in certain cells?

  6. #6
    Registered User
    Join Date
    12-15-2011
    Location
    Dallas texas
    MS-Off Ver
    Excel 2010
    Posts
    45

    Re: How to have 2 Private Sub Worksheet_Changes

    Here is what I need look in columns (G,J,K,N,R,S,V,Z,AA, & AB) and pull up the calendar all other column do nothing

  7. #7
    Registered User
    Join Date
    12-15-2011
    Location
    Dallas texas
    MS-Off Ver
    Excel 2010
    Posts
    45

    Re: How to have 2 Private Sub Worksheet_Changes

    Thanks 46 & 2 that did what i needed.

    Thank you very much!

  8. #8
    Registered User
    Join Date
    06-19-2012
    Location
    Canada Eh
    MS-Off Ver
    Excel 2003, 2007, 2010
    Posts
    40

    Re: How to have 2 Private Sub Worksheet_Changes

    Really? Well then, you are most welcome!

  9. #9
    Registered User
    Join Date
    06-19-2012
    Location
    Canada Eh
    MS-Off Ver
    Excel 2003, 2007, 2010
    Posts
    40

    Re: How to have 2 Private Sub Worksheet_Changes

    Sure, which cells?

  10. #10
    Registered User
    Join Date
    12-15-2011
    Location
    Dallas texas
    MS-Off Ver
    Excel 2010
    Posts
    45

    Re: How to have 2 Private Sub Worksheet_Changes

    Here is the modified code that i have that works but only highlights the entire row if those columns are the active cell.

    Private Sub Worksheet_SelectionChange(ByVal Target As Range)
        If Target.Column = 7 Or Target.Column = 10 Or Target.Column = 11 Or Target.Column = 14 Or Target.Column = 18 Or Target.Column = 19 Or Target.Column = 22 Or Target.Column = 26 Or Target.Column = 27 Or Target.Column = 28 Then
        If Target.NumberFormat = "d/m;@" Then
              CalendarFrm.Show
        End If
        Select Case Target.NumberFormat
            Case Is = "m/d", "m/d", "m/d", "mm/dd", "mmm-dd", "dd-mmm"
            CalendarFrm.Show
        End Select
        
        With thisworkbook.Names("ActiveRow")
            .Name = "ActiveRow"
            .RefersToR1C1 = "=" & ActiveCell.Row
        End With
    
    End If
    End Sub
    Need some help so that any cell will highlight the entire row

+ 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