+ Reply to Thread
Results 1 to 3 of 3

Worksheet_SelectionChange

  1. #1
    Registered User
    Join Date
    11-21-2011
    Location
    Bucuresti
    MS-Off Ver
    Excel 2007
    Posts
    2

    Worksheet_SelectionChange

    Hello,

    I am trying to accomplish the following:
    I have 2 sheets, and i want to exchange some data between them.
    Each time sheet2 is clicked on, i need a script to run.

    Let's say sheet1 is selected, and i have the cell C4 active.
    Eache time i go to sheet2 i need a script to run automaticly.
    The script should take the value from the cell that was active in sheet1(so C4),
    and copy in in sheet2, when i switch to it, in another cell, let's say D8.

    I figured out i need the Worksheet_SelectionChange(ByVal Target As Range) function.
    I guess that "Target", holds the value of the cell that was active in the previous sheet?
    How can i access that value?
    I tried Target.Value but it didn't work.

    If someone could help me i would appriciate it verry much!

    Thank you!

  2. #2
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS365 Family 64-bit
    Posts
    24,721

    Re: Problems with Worksheet_SelectionChange

    There can only be one active/selected cell at a time. When you click on another worksheet, Excel does not provide a way to tell you what the previous selected cell was.

    When Worksheet_Change is called, Target is the newly selected cell in that worksheet.

    What I suggest is creating a public global variable in the code for Sheet1, and updating it every time there is a selection change in that sheet.
    Please Login or Register  to view this content.
    Then in Sheet2, use this:
    Please Login or Register  to view this content.
    Last edited by 6StringJazzer; 11-21-2011 at 02:17 PM. Reason: fixed coding
    Jeff
    | | |會 |會 |會 |會 | |:| | |會 |會
    Read the rules
    Use code tags to [code]enclose your code![/code]

  3. #3
    Registered User
    Join Date
    11-21-2011
    Location
    Bucuresti
    MS-Off Ver
    Excel 2007
    Posts
    2

    Re: Problems with Worksheet_SelectionChange

    Worked, :D

    Thank you very much!

+ 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