Results 1 to 6 of 6
  1. #1
    3 Star Lounger
    Join Date
    Jan 2001
    Location
    Baltimore, MD, Maryland, USA
    Posts
    254
    Thanks
    0
    Thanked 0 Times in 0 Posts

    SelectionChange(ByVal Target As Excel.Range) (OFFICE 97 SR2)

    Hi Again:
    On a number of occasions, I have tried inserting code into the Private Sub Worksheet_SelectionChange(ByVal Target As Excel.Range) Sub and usually have ended up having problems. I have found that whenever my code activates another worksheet, the operations I try to perform result in errors. So, if I have to perform operations on another WS, I put the code in a Module and call the appropriate sub in that Module. This works but I don't know if there are any other limitations that I should be aware of and would appreciate it someone could give me a short disertation on the subject.
    Thanks <img src=/S/woof.gif border=0 alt=woof width=15 height=15>

  2. #2
    3 Star Lounger
    Join Date
    Jan 2001
    Location
    Flims, Switzerland
    Posts
    271
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: SelectionChange(ByVal Target As Excel.Range) (OFFICE 97 SR2)

    the problem may well in lie in what you are trying to do in that code... could you paste an example of something that goes wrong?

  3. #3
    3 Star Lounger
    Join Date
    Jan 2001
    Location
    Baltimore, MD, Maryland, USA
    Posts
    254
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: SelectionChange(ByVal Target As Excel.Range) (OFFICE 97 SR2)

    Hello Adam:
    I don't think that the code is the problem because, when I cut the code from the SelectionChange(ByVal Target As Excel.Range sheet and paste it into a Module as a sub, I can call the sub and get the results that I want. What does not work is when I write code into the SelectionChange(ByVal Target As Excel.Range) sheet which uses "WorkSheets("newSheet").Activate. It seems like the active property (focus) reverts back to the sheet with the CommandClick button on it making the remaining lines of code fail.
    If you still want tme to post some code, let me know.
    Thanks

  4. #4
    3 Star Lounger
    Join Date
    Jan 2001
    Location
    Flims, Switzerland
    Posts
    271
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: SelectionChange(ByVal Target As Excel.Range) (OFFICE 97 SR2)

    You should be able to write just about anything you want in this event handler, as long as the correct object references are used in regard to the current context.

    I might be better if you post some code so I can see exactly what kind of line of code is going wrong. I could try write a dissertation of how things work in this context, but it think it would be easier and quicker to demonstrate by example.

  5. #5
    3 Star Lounger
    Join Date
    Mar 2001
    Location
    Silicon Valley, California, USA
    Posts
    273
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: SelectionChange(ByVal Target As Excel.Range) (OFFICE 97 SR2)

    I will attempt a mini-dissertation:

    Just because something works outside of the SelectionChange context, does not mean that it will work inside the SelectionChange context. For example, if the code in question changes the selection, putting that code inside the SelectionChange context creates a circular reference of sorts.

    However, if you can, please post the code, a concrete analysis is better.

  6. #6
    3 Star Lounger
    Join Date
    Jan 2001
    Location
    Baltimore, MD, Maryland, USA
    Posts
    254
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: SelectionChange(ByVal Target As Excel.Range) (OFFICE 97 SR2)

    Jim:
    I think that you are correct in your analysis. I have been trying to get time to reconstruct what happened and how I corrected the problem. When I can recreate the scenario, I will post it.
    Thanks

Posting Permissions

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