PDA

View Full Version : Solved: Double Click, Insert Character



Hoopsah
07-22-2008, 12:50 AM
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.

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


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

Bob Phillips
07-22-2008, 02:27 AM
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

Hoopsah
07-22-2008, 02:49 AM
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

Bob Phillips
07-22-2008, 03:05 AM
That is odd, I don't.

Does it also happen with this?



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

Hoopsah
07-22-2008, 04:54 AM
Hi Bob,

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

If .Value = Chr(252) Then

Gerry

grichey
07-22-2008, 05:16 AM
Bob's code works for me.

Hoopsah
07-22-2008, 06:01 AM
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

Bob Phillips
07-22-2008, 06:33 AM
How about posting the workbook?

Hoopsah
07-22-2008, 06:34 AM
:doh:

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

Bob Phillips
07-22-2008, 06:58 AM
The bane of merged cells, no I wonder I don't use them.

I should always ask that s the standard first question.

mdmackillop
07-22-2008, 10:05 AM
If you must use merged cells then

With Target(1)
'etc.