Results 1 to 5 of 5
  1. #1
    2 Star Lounger
    Join Date
    Sep 2003
    Location
    Toronto, Ontario, Canada
    Posts
    124
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Selected Cell Condition (2003)

    I'm looking to create a procedure that does something when a specific cell is selected. For example:
    Sub Worksheet_Change
    If Range("A1").'Selected' then
    'do stuff
    End if
    I realize 'selected' isnt an actual property. I think you see what I mean though... Any ideas?

  2. #2
    2 Star Lounger
    Join Date
    Sep 2003
    Location
    Toronto, Ontario, Canada
    Posts
    124
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Selected Cell Condition (2003)

    Perfect, thanks again!

  3. #3
    Uranium Lounger
    Join Date
    Jan 2001
    Location
    South Carolina, USA
    Posts
    7,295
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Selected Cell Condition (2003)

    Hans: I think you code has a major problem. It compares the contents of the active cell with the contents of cell A1 on the active sheet and does stuff if they are equal, even if the active cell is not A1. I think that what you wanted was:

    <pre>Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    Application.EnableEvents = False
    If Not Intersect(Target, Range("A1")) Is Nothing Then
    ' Do stuff, for example
    Beep
    End If
    Application.EnableEvents = True
    End Sub
    </pre>

    Legare Coleman

  4. #4
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Selected Cell Condition (2003)

    You want the Worksheet_SelectionChange event for this. Right-click the worksheet tab and select View Code. Copy the following code into the module:

    Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    Application.EnableEvents = False
    If ActiveCell = Range("A1") Then
    ' Do stuff, for example
    Beep
    End If
    Application.EnableEvents = True
    End Sub

    Note added later: please see Legare Coleman's reply below!

  5. #5
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Selected Cell Condition (2003)

    Thanks, you're entirely correct, I shouldn't have tried to cut a corner!

    I have added a remark to my previous reply.

Posting Permissions

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