Extending sub to cover other target cells

M

Max

How could the sub below* be extended to cover additional cells besides C2,
viz.: the zoom to 120 should work for: C2, C25, C48, C71, C94
(the other cells in col C are offset to the start cell C2 by 24)
*from Debra's site

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Target.Address = "$C$2" Then
ActiveWindow.Zoom = 120
Else
ActiveWindow.Zoom = 100
End If
End Sub

Thanks
 
B

bpeltzer

Instead of
If Target.Address = "$C$2" Then
use
If ((Target.Column = 3) And ((Target.Row Mod 23) = 2)) Then
(This uses steps of 23 per the cell addresses listed; if you need the last
matching cell to be C94, you could further qualify it with "And (Target.Row
<= 94)" ).
 
D

Dave Peterson

I like:

if target.cells.count > 1 then exit sub 'one cell at a time
if intersect(target, me.range("c2,c25,c48,c71,c94")) is nothing then
exit sub
end if

Especially when there doesn't seem to be a pattern.
 
M

Max

Dave, thanks for thoughts and the variation.

Found I had to "swap" the sub's action around
and express it in this way (but it's not a problem):

If Target.Cells.Count > 1 Then Exit Sub 'one cell at a time
If Intersect(Target, Me.Range("c2,c25,c48,c71,c94")) Is Nothing Then
ActiveWindow.Zoom = 100
Else
ActiveWindow.Zoom = 120
Exit Sub
End If
 

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

Top