ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Multiple Target Addresses... (https://www.excelbanter.com/excel-programming/395171-multiple-target-addresses.html)

Brad

Multiple Target Addresses...
 
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Target.Address = "$A$6" Then
Run "Run_Print1"
ElseIf Target.Address = "$A$7" Then
Run "Run_Macro1"
End If
End Sub

Well, the above code works well but I need to have the two macros it runs
depending on the cell selected, be activated by a few more cell selections
in each case. So, where I now only have cell selection A6, I also need to
have A47, A88, A129, A170, and A211 selected cells activate the
'"Run_Print1"' sequence. And, in addition to A7, I need A48, A89, A130,
A171, and A212 for the 'Run_Macro1"' sequence to fire off.

My thanks in advance for any ideas how best to tackle expanding the
selections for Target.Address

Brad





Dan R.

Multiple Target Addresses...
 
Brad,

Try something like this:

Select Case Target.Address
Case "$A$6": ' Do something
Case "$A$7": ' Do something
Case "$A$47": ' Do something
' ... and so on ...
End Select

--
Dan


Tom Ogilvy

Multiple Target Addresses...
 
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
if Target.Count 1 then exit sub
If Not Intersect(Target,Range( _
"A6,A47,A88,A129,A170,A211")) is nothing Then
Run_Print1
ElseIf Not Intersect(Target,Range( _
"A7,A48,A89,A130,A171,A212 ")) is nothing Then
Run_Macro1
End If
End Sub

or

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Select Case Target.Address(0,0)
Case "A6", "A47", "A88", "A129", "A170", "A211"
Run_Print1
Case "A7", "A48", "A89", "A130", "A171", "A212"
Run_Macro1
End Select
End Sub

--
Regards,
Tom Ogilvy

"Brad" wrote:

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Target.Address = "$A$6" Then
Run "Run_Print1"
ElseIf Target.Address = "$A$7" Then
Run "Run_Macro1"
End If
End Sub

Well, the above code works well but I need to have the two macros it runs
depending on the cell selected, be activated by a few more cell selections
in each case. So, where I now only have cell selection A6, I also need to
have A47, A88, A129, A170, and A211 selected cells activate the
'"Run_Print1"' sequence. And, in addition to A7, I need A48, A89, A130,
A171, and A212 for the 'Run_Macro1"' sequence to fire off.

My thanks in advance for any ideas how best to tackle expanding the
selections for Target.Address

Brad







All times are GMT +1. The time now is 02:45 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com