Having multiple Worksheet_Change (ByVal Target As Range) working in the same worksheet

AlexJones1

New Member
Joined
Aug 29, 2023
Messages
2
Office Version
  1. 365
Platform
  1. Windows
Hi, I have managed to code my spreadsheet to allow multiple selections (with no duplicates) from different data lists using the data validation first and then writing the following VBA:
1693316748223.png


The big Target.Address bit in the middle just covers the cells that I want it to work on (it get it might be a bit messy but it's working). However, I am struggling to expand this so it can do it on another cell but instead of inserting a '|' I need it to insert a comma, I have tried repeating the code with the specific cell references with a new private sub but I was getting the ambiguous name error. The only bit I need to change/add in the above coding is different cell references and changing the pipe to a comma.

Thanks,
Alex
 

Excel Facts

Last used cell?
Press Ctrl+End to move to what Excel thinks is the last used cell.
I would suggest approaching it something like this:

VBA Code:
Private Sub worksheet_change(ByVal target As Range)
If Not Intersect(target, Range("M12,M22,M32,M42")) Is Nothing Then
    'do something here
End If

If Not Intersect(target, Range("Z10")) Is Nothing Then
    'do something here
End If

If Not Intersect(target, Range("F43")) Is Nothing Then
    'do something here
End If
End Sub
 
Upvote 0
Hi to all.
Supposing that the other cell is "$L$212" I would use this added code:
VBA Code:
'[...]
If InStr(1, Oldvalue, Newvalue) = 0 Then
    If Target.Address = "$L$212" Then         '<- added
        Target.Value = Oldvalue & "," & Newvalue '<- added
    Else                                      '<- added
        Target.Value = Oldvalue & "|" & Newvalue
    End If
Else:
'[...]
 
Upvote 0
Solution
Thanks both for the suggestion. I managed to get it to work using rollis13's suggestion.
Cheers,
Alex
 
Upvote 0
Thanks for the positive feedback(y), glad we were able to help.
 
Upvote 0

Forum statistics

Threads
1,215,079
Messages
6,122,998
Members
449,092
Latest member
masterms

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top