Consulting

Results 1 to 4 of 4

Thread: Method Intersect Error

  1. #1

    Method Intersect Error

    I have the following code which inserts a signature once a specified cell range is activated. This works fine but once I switch between worsheets using hyperlinks it throws the error "Method Intersect of Object_Global failed". I have the code pasted into the worksheet where the signatures go. I can switch between worksheets without issue but if I click on a hyperlink which I need) to bring me to another worksheet in the same workbook I get the error. I have marked within the code where the debugger brings me.

    Option Explicit
    Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    Set Target = Me.Range("C2:D18")
    'ERROR is here
    If Not Intersect(ActiveCell, Target) Is Nothing Then
    signature
    End If
    End Sub
    
    Sub signature()
    Dim user1 As String
    Dim date1 As Date
    'Sheets("Checklist").Select
    'If Trim(Cells(2, 3)) = "" Then
    If ActiveCell = "" Then
    user1 = Environ("UserName")
    date1 = Now
    ActiveCell = user1 & " @ " & date1
    End If
    End Sub
    Many thanks,

    Des

  2. #2
    VBAX Master Aflatoon's Avatar
    Joined
    Sep 2009
    Location
    UK
    Posts
    1,720
    Location
    I don't really understand why you've written the SelectionChange code the way you have. Target represents the cell that has just been selected - you shouldn't try to change that. I suggest you use:
    [vba]Private Sub Worksheet_SelectionChange(ByVal Target As Range)

    Dim rMonitor As Range
    Set rMonitor = Me.Range("C218")

    'ERROR is here
    If Not Intersect(rMonitor, Target) Is Nothing Then


    Signature



    End If
    End Sub

    [/vba]
    Be as you wish to seem

  3. #3
    Hi Aflatoon,

    That worked perfectly for me so thank you. I think that is about the 5th time you have helped me so I owe you a beer. I am marking this as solved.

    All the best,

    Des

  4. #4
    VBAX Master Aflatoon's Avatar
    Joined
    Sep 2009
    Location
    UK
    Posts
    1,720
    Location
    You're welcome. One day, I'll hold you to that beer.
    Be as you wish to seem

Posting Permissions

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