I’m trying to transform a cell to give the appearance of being a checkbox. By using a Worksheet_BeforeDoubleClick to insert a Bold/ Capitalized X.
The checkboxes provided with excel are to small
or is there a better way to achive this.
I search around trying to find any ideas
I put what small knowledge i have and this is what i was able to get, I'm probabaly off by a mile.
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
If Not Intersect(Range("F9"), Target) Is Nothing Then
Cancel = True
If ActiveSheet.Range("F9").Value = " " Then
Else
ActiveSheet.Range("F9").Value = "X"
End If
End If
End Sub
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
If Not Intersect(Range("F9"), Target) Is Nothing Then
Application.EnableEvents = False
Cancel = True
If Range("F9").Value = "" Then
Range("F9").Value = "X"
Else
Range("F9").Value = ""
End If
Application.EnableEvents = True
End If
End Sub
Last edited by HansV on 16 May 2010, 11:38, edited 1 time in total.
Reason:to remove superfluous reference to ActiveSheet
If you set the font of cell F9 to Wingdings (a font distributed with Windows, so available on all Windows PCs), you can use the empty and filled check box characters from that font:
x128.png
See the attached sample workbook.
SimulateCheckbox.xlsm
You do not have the required permissions to view the files attached to this post.
HansV wrote:If you set the font of cell F9 to Wingdings (a font distributed with Windows, so available on all Windows PCs), you can use the empty and filled check box characters from that font:
Hans, I was curious as to how this could be used on a multi range. I attach my effort which is incorrect for your expert correction:
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
Dim rng As Range
Set rng = Range("F9:F18")
If Not Intersect(Range(rng), Target) Is Nothing Then
Application.EnableEvents = False
Cancel = True
If Range(rng).Value = Chr(254) Then
Range(rng).Value = Chr(168)
Else
Range(rng).Value = Chr(254)
End If
Application.EnableEvents = True
End If
End Sub
In the first place, rng is already a Range object, so it makes no sense to use Range(rng).
In the second place, a multi-cell range doesn't have a single value, so you can't simply test rng.Value.
In general, you'd have to loop through the cells of the intersection, but since the user can only double-click a single cell, we can cut a corner and refer to Target here:
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
Dim rng As Range
Set rng = Range("F9:F18")
If Not Intersect(rng, Target) Is Nothing Then
Application.EnableEvents = False
Cancel = True
If Target.Value = Chr(254) Then
Target.Value = Chr(168)
Else
Target.Value = Chr(254)
End If
Application.EnableEvents = True
End If
End Sub
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
Dim rng As Range
Set rng = Range("F9:F18")
If Not Intersect(rng, Target) Is Nothing Then
Application.EnableEvents = False
Cancel = True
If Target.Value = Chr(254) Then
Target.Value = Chr(168)
Else
Target.Value = Chr(254)
End If
Application.EnableEvents = True
End If
End Sub
I can break the number of cell to at least half and they work fine. I have been messing with this for a while, cant seem to figure what I'm doing wrong.
UPDATE: I am able to use
Set rng = Range("B10:B317,D10:D317,F10:F317,H10:H317")
but then of course I get everything between
Last edited by ABabeNChrist on 17 May 2010, 07:37, edited 1 time in total.