+ Reply to Thread
Results 1 to 5 of 5

Worksheet_Selectionchange for range

Hybrid View

  1. #1
    Registered User
    Join Date
    06-29-2005
    Posts
    77

    Worksheet_Selectionchange for range

    Hi

    I hve this code:

    Private sub Worksheet_Selectionchange(ByVal Target As Range)
    
    if target.address="$B$4" then
    msgbox"Hello"
    end if
    end sub
    But I want this to work for a range of cells on the sheet, i.e.:

    Private sub Worksheet_Selectionchange(ByVal Target As Range)
    
    if target.RANGE="A2:E4" then
    msgbox "Hello"
    end if
    end sub
    Ideas welcome

    tx

  2. #2
    Jim Thomlinson
    Guest

    RE: Worksheet_Selectionchange for range

    Private sub Worksheet_Selectionchange(ByVal Target As Range)

    if not intersect(target, Range("A2:E4")) is nothing then
    msgbox"Hello"
    end if
    end sub

    --
    HTH...

    Jim Thomlinson


    "tx12345" wrote:

    >
    > Hi
    >
    > I hve this code:
    >
    >
    > Code:
    > --------------------
    > Private sub Worksheet_Selectionchange(ByVal Target As Range)
    >
    > if target.address="$B$4" then
    > msgbox"Hello"
    > end if
    > end sub
    >
    > --------------------
    >
    >
    > But I want this to work for a range of cells on the sheet, i.e.:
    >
    >
    > Code:
    > --------------------
    > Private sub Worksheet_Selectionchange(ByVal Target As Range)
    >
    > if target.RANGE="A2:E4" then
    > msgbox "Hello"
    > end if
    > end sub
    >
    >
    >
    > --------------------
    >
    >
    > Ideas welcome
    >
    > tx
    >
    >
    > --
    > tx12345
    > ------------------------------------------------------------------------
    > tx12345's Profile: http://www.excelforum.com/member.php...o&userid=24776
    > View this thread: http://www.excelforum.com/showthread...hreadid=571940
    >
    >


  3. #3
    Die_Another_Day
    Guest

    Re: Worksheet_Selectionchange for range

    Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    If Intersect(Target, Range("A2:E4")) Is Nothing Then
    MsgBox "Out of Range"
    Else
    MsgBox "In Range"
    End If
    End Sub

    HTH

    Charles Chickering

    tx12345 wrote:
    > Hi
    >
    > I hve this code:
    >
    >
    > Code:
    > --------------------
    > Private sub Worksheet_Selectionchange(ByVal Target As Range)
    >
    > if target.address="$B$4" then
    > msgbox"Hello"
    > end if
    > end sub
    >
    > --------------------
    >
    >
    > But I want this to work for a range of cells on the sheet, i.e.:
    >
    >
    > Code:
    > --------------------
    > Private sub Worksheet_Selectionchange(ByVal Target As Range)
    >
    > if target.RANGE="A2:E4" then
    > msgbox "Hello"
    > end if
    > end sub
    >
    >
    >
    > --------------------
    >
    >
    > Ideas welcome
    >
    > tx
    >
    >
    > --
    > tx12345
    > ------------------------------------------------------------------------
    > tx12345's Profile: http://www.excelforum.com/member.php...o&userid=24776
    > View this thread: http://www.excelforum.com/showthread...hreadid=571940



  4. #4
    Bob Phillips
    Guest

    Re: Worksheet_Selectionchange for range

    Private sub Worksheet_Selectionchange(ByVal Target As Range)

    if not intersect(target, RANGE("A2:E4")) is nothing then
    msgbox "Hello"
    end if
    end sub


    --
    HTH

    Bob Phillips

    (replace somewhere in email address with gmail if mailing direct)

    "tx12345" <[email protected]> wrote in
    message news:[email protected]...
    >
    > Hi
    >
    > I hve this code:
    >
    >
    > Code:
    > --------------------
    > Private sub Worksheet_Selectionchange(ByVal Target As Range)
    >
    > if target.address="$B$4" then
    > msgbox"Hello"
    > end if
    > end sub
    >
    > --------------------
    >
    >
    > But I want this to work for a range of cells on the sheet, i.e.:
    >
    >
    > Code:
    > --------------------
    > Private sub Worksheet_Selectionchange(ByVal Target As Range)
    >
    > if target.RANGE="A2:E4" then
    > msgbox "Hello"
    > end if
    > end sub
    >
    >
    >
    > --------------------
    >
    >
    > Ideas welcome
    >
    > tx
    >
    >
    > --
    > tx12345
    > ------------------------------------------------------------------------
    > tx12345's Profile:

    http://www.excelforum.com/member.php...o&userid=24776
    > View this thread: http://www.excelforum.com/showthread...hreadid=571940
    >




  5. #5
    Registered User
    Join Date
    06-29-2005
    Posts
    77
    Thanks. Works perfectly.


    tx

+ 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