ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Extending sub to cover other target cells (https://www.excelbanter.com/excel-programming/347400-extending-sub-cover-other-target-cells.html)

Max

Extending sub to cover other target cells
 
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
--
Rgds
Max
xl 97
---
Singapore, GMT+8
xdemechanik
http://savefile.com/projects/236895
--



Max

Extending sub to cover other target cells
 
Oops, line
(the other cells in col C are offset to the start cell C2 by 24)


should read:
(the other cells in col C are offset to the start cell C2 by steps of 24)


--
Rgds
Max
xl 97
---
Singapore, GMT+8
xdemechanik
http://savefile.com/projects/236895
--



bpeltzer

Extending sub to cover other target cells
 
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)" ).

"Max" wrote:

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
--
Rgds
Max
xl 97
---
Singapore, GMT+8
xdemechanik
http://savefile.com/projects/236895
--




Max

Extending sub to cover other target cells
 
Thanks, bpeltzer !
That works great.
--
Rgds
Max
xl 97
---
Singapore, GMT+8
xdemechanik
http://savefile.com/projects/236895
--
"bpeltzer" wrote in message
...
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)" ).




Dave Peterson

Extending sub to cover other target cells
 
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.

Max wrote:

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
--
Rgds
Max
xl 97
---
Singapore, GMT+8
xdemechanik
http://savefile.com/projects/236895
--


--

Dave Peterson


All times are GMT +1. The time now is 11:40 AM.

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