+ Reply to Thread
Results 1 to 6 of 6

Private Sub Worksheet_Change(ByVal Target As Range) - 2 on one worksheet?

Hybrid View

  1. #1
    Registered User
    Join Date
    09-22-2013
    Location
    Aurora, Colorado
    MS-Off Ver
    Excel 2007
    Posts
    30

    Private Sub Worksheet_Change(ByVal Target As Range) - 2 on one worksheet?

    I'm sorry but I probably have a dumb question. I can run a Private Sub Worksheet_Change(ByVal Target As Range) macro and a Private Sub Worksheet_SelectionChange(ByVal Target As Range) macro on the same Worksheet (note: "SelectionChange" is the difference). Is there another option that I can use at the beginning of a third macro so it will be compatible with the above 2? When I have two of the same then I get an error message.

  2. #2
    Forum Expert
    Join Date
    07-31-2010
    Location
    California
    MS-Off Ver
    Excel 2007
    Posts
    4,070

    Re: Private Sub Worksheet_Change(ByVal Target As Range) - 2 on one worksheet?

    I am confused, what do you mean by a third macro? You can do multiple stuff inside each event. Also, what about the selectionchange vs the change is causing you issues? Do you even really need to be doing it that way?

    What is it you are trying to accomplish?

  3. #3
    Registered User
    Join Date
    09-22-2013
    Location
    Aurora, Colorado
    MS-Off Ver
    Excel 2007
    Posts
    30

    Re: Private Sub Worksheet_Change(ByVal Target As Range) - 2 on one worksheet?

    Hi: I guess I'm confused how to combine the 3 things I am trying to do on two sheets. The following is my code, the last one I've put a ' in front of everything to stop it from running and creating an error (but want it incorporated). Hope this explains what I am trying to do, I realize that I may be doing things in a very unorthodox way. I would appreciate your help.



    'This is Option A to Concatenate drawing info
    Private Sub Worksheet_SelectionChange(ByVal Target As Range)
       Dim rng As Range
       Set rng = Target.Parent.Range("D3:D1000")
       If Target.Count > 1 Then Exit Sub
       If Intersect(Target, rng) Is Nothing Then Exit Sub
       Target.Offset(, 6).Value = _
           Target.Offset(, 1) & " " & Target.Offset(, 5) & " " & Target.Offset(, 3)
               
    End Sub
    
    'This is option A to add hyperlink automatically
    Private Sub Worksheet_Change(ByVal Target As Range)
        Dim Rws As Long, sh As Worksheet
        Set sh = Worksheets("CABLE_MATRIX")
        With sh
            Rws = .Cells(Rows.Count, "A").End(xlUp).Row + 1
        End With
    
        If Target.Count > 1 Or Target.Column <> 11 Then Exit Sub
        If InStr(Target, "Cable Assy") <> 0 Then
            ActiveSheet.Hyperlinks.Add Anchor:=Target.Offset(0, 5), Address:="", SubAddress:= _
                                       "CABLE_MATRIX!A" & Rws, TextToDisplay:="CABLE_MATRIX!A" & Rws
        End If
    End Sub
    
    'This will automatically provide Mad Cat date
    'Private Sub Worksheet_Change(ByVal Target As Range)
    
    'Set t = Target
    'Set A = Range("$B$3:$B$2500")
    'If Target.Count > 1 Then Exit Sub
    'If Intersect(t, A) Is Nothing Then Exit Sub
    'Application.EnableEvents = False
    't.Offset(0, 10).Value = Date
    'Application.EnableEvents = True
    'End Sub

  4. #4
    Registered User
    Join Date
    09-22-2013
    Location
    Aurora, Colorado
    MS-Off Ver
    Excel 2007
    Posts
    30

    Re: Private Sub Worksheet_Change(ByVal Target As Range) - 2 on one worksheet?

    And when I say, "to combine the 3 things I am trying to do on two sheets" I mean that this code is doing things to my Worksheets 1 and 2 in my Workbook. I currently have all of this code on Sheet 1.

  5. #5
    Forum Expert
    Join Date
    07-31-2010
    Location
    California
    MS-Off Ver
    Excel 2007
    Posts
    4,070

    Re: Private Sub Worksheet_Change(ByVal Target As Range) - 2 on one worksheet?

    You still haven't described what you are trying to accomplish with your code. I can see what you code does but it doesn't mean that it is doing what you hope it is doing.

    With regards to combining the Worksheet_Change, all I can say is with Worksheet_Change you specify the range or ranges that you want some code to occur. You can have as many ranges as you want.

    Example:

    Your two codes would be within one Worksheet_Change event. One would only trigger if the changed cell is in the named range "Cable Assy", the other would trigger if the changed cell is in B3:B2500. Now if the two ranges are the same then you are going to have to do some other defining. But since I have no idea what you are trying to do i can't help you.

  6. #6
    Registered User
    Join Date
    09-22-2013
    Location
    Aurora, Colorado
    MS-Off Ver
    Excel 2007
    Posts
    30

    Re: Private Sub Worksheet_Change(ByVal Target As Range) - 2 on one worksheet?

    Sorry I don't know enough to explain this very well but I'll try. When I isolate the 3 different macros they work fine, it is just getting them all to play together nicely. I don't understand how to combine the 2 that start with: Private Sub Worksheet_Change. If I combine a "Private Sub Worksheet_Change" and a "Private Sub Worksheet_SelectionChange then I can get two of them to work.

+ 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] Private Sub Worksheet_Change(ByVal Target As Range) End Sub
    By kanonathena in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 09-10-2013, 12:25 AM
  2. Private Sub Worksheet_Change(ByVal Target As Range) Help
    By adamsj1 in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 10-28-2012, 09:17 AM
  3. [SOLVED] Private Sub Worksheet_Change(ByVal Target As Range)
    By adamsj1 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 10-12-2012, 03:36 AM
  4. [SOLVED] Private Sub Worksheet_Change(ByVal Target As Range)
    By Hilton1982 in forum Excel Programming / VBA / Macros
    Replies: 14
    Last Post: 09-18-2012, 01:13 AM
  5. [SOLVED] Private Sub Worksheet_Change(ByVal Target As Range)
    By Arturo in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 05-25-2005, 11:06 AM

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