Multiple VBA Codes on One Sheet

ahamed

Board Regular
Joined
Jan 11, 2011
Messages
114
Hi everone!!

I have following code (code1) in my excel sheet and I want this same processed to be run in the same sheet in two different places for two different purpose (for 2 different set of data)

Code 1 is working well, when I try to develop code-2 (as smellier to code1) it seems not working. Please advice me ,,

How should I modify code2 to make it work.


(FYI- each code has 4 different name range)

Thanking you,,,


Code 1

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Not Application.Intersect(ActiveCell, [plstProduct]) Is Nothing Then
[valProductPick] = ActiveCell.Value
ElseIf Not Application.Intersect(ActiveCell, [plstCategory]) Is Nothing Then
[valCategoryPick] = ActiveCell.Value
End If
End Sub

Code 2

Private Sub Worksheet_SelectionChange2(ByVal Target As Range)
If Not Application.Intersect(ActiveCell, [plstProduct2]) Is Nothing Then
[valProductPick2] = ActiveCell.Value
ElseIf Not Application.Intersect2(ActiveCell, [plstCategory2]) Is Nothing Then
[valCategoryPick2] = ActiveCell.Value
End If
End Sub
 
Last edited:

Excel Facts

What do {} around a formula in the formula bar mean?
{Formula} means the formula was entered using Ctrl+Shift+Enter signifying an old-style array formula.
That isn't how the sheet events work, You need to have it all in the one event with a case statement or bunch of If's to work out what you want it to do based on the target.address.

What is the criteria that will determine which code should fire?
 
Upvote 0
Thanks for your kind and quick reply..

I am totally new to VBA,, I can only manage to borrow some codes and make it run,

I am not sure, whether I can make it what you have mentioned above, I gonna try anyway once.. :)

Thanks again.
 
Upvote 0

Forum statistics

Threads
1,214,553
Messages
6,120,176
Members
448,948
Latest member
spamiki

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