+ Reply to Thread
Results 1 to 11 of 11

Two Cells as Event Target Problem

Hybrid View

  1. #1
    Registered User
    Join Date
    04-25-2011
    Location
    New York, USA
    MS-Off Ver
    Excel 2007
    Posts
    13

    Smile Two Cells as Event Target Problem

    Hi I have this that zooms if cell you are on cell G4 in Excel 2007 how can I make two cells to zoom, it tried different ways. Please advise hot to make multiple if statements with ELSE.
    This does not work.
    Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    If Target.Address = "$G$4" Then
      ActiveWindow.Zoom = 100
        Else
      ActiveWindow.Zoom = 52
      End If
        If Target.Address = "$F$4" Then
      ActiveWindow.Zoom = 100
      Else
      ActiveWindow.Zoom = 52
    End If
    End Sub

    With one Target address it works! Confused!
    Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    If Target.Address = "$G$4" Then
      ActiveWindow.Zoom = 100
        Else
      ActiveWindow.Zoom = 52
      End If
    End Sub
    Thanks
    Last edited by sidney102; 04-25-2011 at 04:11 PM.

  2. #2
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Help with VB in Excel

    Hi Sidney... Welcome to the forum.

    Be sure to read through the Forum Rules so you can use and follow them effectively. For instance, you'll need to EDIT that post above and put code tags around that code you used. (Like shown in my signature)

    Your question is a simple one, so add the code tags and replace the title with a description of the problem, then you'll get rapid suggestions, I promise.
    _________________
    Microsoft MVP 2010 - Excel
    Visit: Jerry Beaucaire's Excel Files & Macros

    If you've been given good help, use the icon below to give reputation feedback, it is appreciated.
    Always put your code between code tags. [CODE] your code here [/CODE]

    ?None of us is as good as all of us? - Ray Kroc
    ?Actually, I *am* a rocket scientist.? - JB (little ones count!)

  3. #3
    Registered User
    Join Date
    04-25-2011
    Location
    New York, USA
    MS-Off Ver
    Excel 2007
    Posts
    13

    Re: Help with VB in Excel

    ok, I updated the post
    Last edited by sidney102; 04-25-2011 at 04:09 PM.

  4. #4
    Forum Guru MarvinP's Avatar
    Join Date
    07-23-2010
    Location
    Woodinville, WA
    MS-Off Ver
    Office 365
    Posts
    16,169

    Re: Help with VB in Excel

    Hi Sidney102 and welcome to the forum.

    First, could you edit your post, by clicking on the green "Edit" and then click on "Go Advanced". Change the thread title to something like "Two Cells as Event Target Problem". This will make it much easier to find and help others who may have the same question. Your current title of "Help with VB in Excel" is just too broad to help others. Also - Read the forum rules to see what they suggest as a good title.

    Now on to your answer. How about using OR?

    Darn - I just realized you should put code above in code tags also. To do that you need to click on "Go Advanced" like above and select that text that is code and then click on the "#" icon above the advanced message area.

    I'll be in trouble if I answer your question without you fixing your post. You fix the two above problems and I'll give you my answer to yours.
    One test is worth a thousand opinions.
    Click the * Add Reputation below to say thanks.

  5. #5
    Registered User
    Join Date
    04-25-2011
    Location
    New York, USA
    MS-Off Ver
    Excel 2007
    Posts
    13

    Smile Two Cells as Event Target Problem

    Hi How do I use OR in this problem?

    Private Sub Worksheet_SelectionChange(ByVal Target As Range)
      If Target.Address = "$G$4" Then
      ActiveWindow.Zoom = 100
        Else
      ActiveWindow.Zoom = 52
      End If
      If Target.Address = "$F$4" Then
      ActiveWindow.Zoom = 100
      Else
      ActiveWindow.Zoom = 52
    End If
    End Sub
    Last edited by sidney102; 04-25-2011 at 04:05 PM.

  6. #6
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Two Cells as Event Target Problem

    Please do not use the QUOTE button, we already know what has been said, repeating it is pointless. Use the Quick Reply box below.

    Now you have TWO posts to fix. Please edit post #1 and #5, then click GO ADVANCED, highlight the code portion and click the # icon to put code tags around it. Like so:

    Sub Macro1()
        This is properly formatted
    End Sub

  7. #7
    Registered User
    Join Date
    04-25-2011
    Location
    New York, USA
    MS-Off Ver
    Excel 2007
    Posts
    13

    Re: Two Cells as Event Target Problem

    Ok, I updated the question with the proper quote.

  8. #8
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: Two Cells as Event Target Problem

    How about this?

    Private Sub Worksheet_SelectionChange(ByVal Target As Range)
        Select Case Target.Address
            Case "$G$4", "$F$4"
                ActiveWindow.Zoom = 100
            Case Else
                ActiveWindow.Zoom = 52
        End Select
    End Sub
    Entia non sunt multiplicanda sine necessitate

  9. #9
    Registered User
    Join Date
    04-25-2011
    Location
    New York, USA
    MS-Off Ver
    Excel 2007
    Posts
    13

    Re: Two Cells as Event Target Problem

    Works perfect

  10. #10
    Forum Guru MarvinP's Avatar
    Join Date
    07-23-2010
    Location
    Woodinville, WA
    MS-Off Ver
    Office 365
    Posts
    16,169

    Re: Two Cells as Event Target Problem

    Hi,
    Here is the OR solution:
    Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    If Target.Address = "$G$4" Or Target.Address = "$F$4" Then
      ActiveWindow.Zoom = 100
        Else
      ActiveWindow.Zoom = 52
      End If
    End Sub

  11. #11
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Two Cells as Event Target Problem

    If that takes care of your need, please click EDIT in your original post, click GO ADVANCED and set the PREFIX box to SOLVED.

+ 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