Consulting

Results 1 to 11 of 11

Thread: Solved: Double Click, Insert Character

  1. #1
    VBAX Mentor Hoopsah's Avatar
    Joined
    Nov 2007
    Posts
    303
    Location

    Solved: Double Click, Insert Character

    Hi,

    wonder if this is possible.

    I had a look at a piece of coding someone had posted on here so that if you double click a cell it will change the colour of the text in that cell.

    [VBA]Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
    If Target.Font.ColorIndex = 10 Then
    Target.Font.ColorIndex = 3
    Cancel = True
    Exit Sub
    End If
    If Target.Font.ColorIndex = 3 Then
    Target.Font.ColorIndex = xlAutomatic
    Cancel = True
    Exit Sub
    End If
    Target.Font.ColorIndex = 10
    Cancel = True
    End Sub
    [/VBA]

    What i would like to be able to do, is to double click and it will insert a symbol into the cell. Wingdings character 252 - a big tick (Can't find a big cross yet)

    I have tried doing a validation, but the drop down option shows as 'u' (With a wee tilda over it)

    If not I will try something else, but just in case anyone knows if this is possible and how to do it,

    Thanks for your help guys

    Hoopsah
    I am playing all the right notes, but not necessarily in the right order.
    Eric Morecambe

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    [vba]

    Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)

    With Target

    Cancel = True
    If .Value = "?" Then

    .Value = ""
    Else

    .Value = "?"
    .Font.Name = "Wingdings"
    End If
    End With
    End Sub
    [/vba]
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  3. #3
    VBAX Mentor Hoopsah's Avatar
    Joined
    Nov 2007
    Posts
    303
    Location
    Hi Bob,

    when I add this code to the code on the worksheet, I double click on a cell and I get a pop-up saying Run Time Error '13' - Type mismatch

    Any ideas

    Gerry
    I am playing all the right notes, but not necessarily in the right order.
    Eric Morecambe

  4. #4
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    That is odd, I don't.

    Does it also happen with this?

    [vba]

    Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)

    With Target

    Cancel = True
    If .Value = Chr(252) Then

    .Value = ""
    Else

    .Value = Chr(252)
    .Font.Name = "Wingdings"
    End If
    End With
    End Sub
    [/vba]
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  5. #5
    VBAX Mentor Hoopsah's Avatar
    Joined
    Nov 2007
    Posts
    303
    Location
    Hi Bob,

    yes same error. When I click on de-bug it is highlighting the following line:

    If .Value = Chr(252) Then

    Gerry
    I am playing all the right notes, but not necessarily in the right order.
    Eric Morecambe

  6. #6
    VBAX Mentor
    Joined
    Oct 2007
    Posts
    372
    Location
    Bob's code works for me.

  7. #7
    VBAX Mentor Hoopsah's Avatar
    Joined
    Nov 2007
    Posts
    303
    Location
    Cheers Gavin,

    I am copying the code as is, right clicking the tab name and selecting View Code,

    I then paste it into the VBA window.

    Am I missing something or not doind something right?

    Cheers guys

    Gerry
    I am playing all the right notes, but not necessarily in the right order.
    Eric Morecambe

  8. #8
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    How about posting the workbook?
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  9. #9
    VBAX Mentor Hoopsah's Avatar
    Joined
    Nov 2007
    Posts
    303
    Location


    Would you believe this, I had the cells merged!!!!

    Thanks once again Bob, code works perfectly (Sorry for doubting you)

    And Cheers Gavin, once you had said it worked for you then I examined what I was doing a bit harder.

    Once again, I will mark this as solved and a massive thank you to XLD

    Pure Cheers

    Hoopsah
    I am playing all the right notes, but not necessarily in the right order.
    Eric Morecambe

  10. #10
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    The bane of merged cells, no I wonder I don't use them.

    I should always ask that s the standard first question.
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  11. #11
    Administrator
    VP-Knowledge Base
    VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    If you must use merged cells then
    [VBA]
    With Target(1)
    'etc.

    [/VBA]
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

Posting Permissions

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