+ Reply to Thread
Results 1 to 3 of 3

BeforeDoubleClick Error 13 Type Mismatch - please help :)

Hybrid View

Bonnister BeforeDoubleClick Error 13... 01-25-2013, 08:43 AM
HaHoBe Re: BeforeDoubleClick Error... 01-26-2013, 06:31 AM
Bonnister Re: BeforeDoubleClick Error... 01-28-2013, 06:18 AM
  1. #1
    Registered User
    Join Date
    03-01-2012
    Location
    Nottingham, England
    MS-Off Ver
    Excel 2010
    Posts
    64

    BeforeDoubleClick Error 13 Type Mismatch - please help :)

    Hello all

    I'm using the following code in my workbook:

    Option Explicit
    
    Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
        
    If Not Intersect(Target, Range("g28:bx48")) Is Nothing Then
    Cancel = True
    
    If Target.Value = "No" Then
    Target.Value = "Yes"
    Else
    Target.Value = "No"
     
    End If
    End If
    
    End Sub
    However when I double click in the range the following error appears:

    Run-Time Error 13 - Type Mismatch

    I understand why the error is occuring - the worksheet is set up such that every 'cell' I click in within the range G28:BX48 comprises several columns merged into one cell (specifically 7 columns and 1 row). Every 'cell' in the range has the same merging conditions, ie: 7 columns, 1 row.

    Is it possible to amend my code so that it recognises the 'target' as a merged cell range rather than a single cell? If so how do I do this please??

    Any help is appreciated

    Thank you all

    Kenny
    Last edited by Bonnister; 01-25-2013 at 08:46 AM. Reason: forgot to add tags to my post

  2. #2
    Forum Guru HaHoBe's Avatar
    Join Date
    02-19-2005
    Location
    Hamburg, Germany
    MS-Off Ver
    work: 2016 on Win10 (notebook), private: 365 on Win11 (desktop), 2019 on Win11 (notebook)
    Posts
    8,198

    Re: BeforeDoubleClick Error 13 Type Mismatch - please help :)

    Hi, Kenny,

    best use would be to avoid any merged cells. You could try using MergeArea for determining the merged cells or maybe just try
    Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
        
    If Not Intersect(Target, Range("g28:bx48")) Is Nothing Then
      Cancel = True
      With Target.Cells(1)
        If .Value = "No" Then
          .Value = "Yes"
        Else
          .Value = "No"
        End If
      End With
    End If
    
    End Sub
    or
    Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
        
    If Not Intersect(Target, Range("g28:bx48")) Is Nothing Then
      Cancel = True
      With Target.Cells(1)
        .Value = IIf(.Value = "No", "Yes", "No")
      End With
    End If
    
    End Sub
    Ciao,
    Holger
    Use Code-Tags for showing your code: [code] Your Code here [/code]
    Please mark your question Solved if there has been offered a solution that works fine for you

  3. #3
    Registered User
    Join Date
    03-01-2012
    Location
    Nottingham, England
    MS-Off Ver
    Excel 2010
    Posts
    64

    Re: BeforeDoubleClick Error 13 Type Mismatch - please help :)

    Hi Holger

    Both solutions work a treat, agree with you about avoiding merged cells although in this instance the worksheet can't really avoid it without a thorough rebuild which isn't viable.

    Thanks for your help

    Kenny

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

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