+ Reply to Thread
Results 1 to 3 of 3

Worksheet_SelectionChange script errors for unknown reason

Hybrid View

  1. #1
    Registered User
    Join Date
    09-29-2012
    Location
    United Kingdom
    MS-Off Ver
    Excel 2010
    Posts
    1

    Worksheet_SelectionChange script errors for unknown reason

    Hi there

    My VBA code is giving me trouble (Excel 2010). This is supposed to trigger another macro (using Worksheet_SelectionChange) if the cell selected is in column 10 and row 5 onwards, and contains particular text. The script works fine normally, but in U5, where it should not do anything, this code shows up in yellow.

    If Target(1, 1).Column = 10 And Target(1, 1).Row > 4 And Target(1, 1).Value = "McMillan" Then
    Any ideas?

    Thanks.

  2. #2
    Forum Expert Palmetto's Avatar
    Join Date
    04-04-2007
    Location
    South Eastern, USA
    MS-Off Ver
    XP, 2007, 2010
    Posts
    3,978

    Re: Worksheet_SelectionChange script errors for unknown reason

    I would use the Intersect Method

    If Not Intersect(Target, Range("J5:J100")) Is Nothing Then
        If Target.Value = "McMillian" Then
        
        End If
    End If
    Adjust the range reference to suit - it could be made dynamic so that additional rows are accounted for you expect data beyond row 100.
    Palmetto

    Do you know . . . ?

    You can leave feedback and add to the reputation of all who contributed a helpful response to your solution by clicking the star icon located at the left in one of their post in this thread.

  3. #3
    Forum Expert OllieB's Avatar
    Join Date
    12-20-2012
    Location
    Netherlands
    MS-Off Ver
    Excel 2007 (home) & 2010 (office)
    Posts
    1,542

    Re: Worksheet_SelectionChange script errors for unknown reason

    I would use:

         If Target.Column = 10 Then
              If Target.Row > 4 And Target.Value = "McMillan" Then
                   'execute code
              End If
         End If
    If you like my contribution click the star icon!

+ 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