+ Reply to Thread
Results 1 to 6 of 6

Extending sub to cover other target cells

  1. #1
    Max
    Guest

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



  2. #2
    Max
    Guest

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



  3. #3
    bpeltzer
    Guest

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


  4. #4
    Max
    Guest

    Re: 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" <[email protected]> wrote in message
    news:[email protected]...
    > 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)" ).




  5. #5
    Dave Peterson
    Guest

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

  6. #6
    Max
    Guest

    Re: Extending sub to cover other target cells

    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

    --
    Rgds
    Max
    xl 97
    ---
    Singapore, GMT+8
    xdemechanik
    http://savefile.com/projects/236895
    --
    "Dave Peterson" <[email protected]> wrote in message
    news:[email protected]...
    > 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.




+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1