Multiple Target Addresses...

  • Thread starter Thread starter Brad
  • Start date Start date
B

Brad

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
 
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
 
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top