Using VBA in EXCEL to add a checkmark to a cell

Robert_Conklin

Board Regular
Joined
Jun 19, 2017
Messages
173
Office Version
  1. 365
Platform
  1. Windows
  2. MacOS
I use the checkmark symbol a lot and I would like to use a macro to add a checkmark to a cell that I select. I tried recording a macro to add a checkmark to a selected cell but I need it set up so that it will place a checkmark in any cell that I select, not just the one that the recording filled in. Below is the recorded macro;

VBA Code:
Sub Insert_A_Checkmark()

' Insert_A_Checkmark Macro

    ActiveCell.FormulaR1C1 = "ü"
    Range("G18").Select
End Sub

Any help would be greatly appreciated.
 

Excel Facts

Why does 9 mean SUM in SUBTOTAL?
It is because Sum is the 9th alphabetically in Average, Count, CountA, Max, Min, Product, StDev.S, StDev.P, Sum, VAR.S, VAR.P.
In a standard code module (where your old sub is), this is code to put a green checkmark centered horizontally and vertically:
VBA Code:
Sub Test__Insert_Symbol_On_ThisTile()
Call Insert_Symbol_In_This_Cell(ActiveCell.Address, "00FC", "Wingdings")
End Sub
Sub Insert_Symbol_In_This_Cell(cellAddress As String, hexcode As String, fontName As String)
With Range(cellAddress)
    .HorizontalAlignment = xlCenter
    .VerticalAlignment = xlCenter
    .Font.Color = RGB(0, 255, 0)
    .Value = ChrW("&h" & hexcode)
    .Font.Name = LCase(fontName)
End With
End Sub

Now right click on the sheet tab name of the sheet that you want this to happen and click View Code:
View code.PNG

And copy the following code into there:
VBA Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Target.Cells.Count = 1 Then Call Insert_Symbol_In_This_Cell(Target.Address, "00FC", "Wingdings")
End Sub

EDIT:

But the above sheetcode will only put checkmarks! If you want it to remove the checkmark if you click on a cell that has one (but not on the same cell that you just put one but didn't make another selection first), then use this code in the sheet instead.
VBA Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Target.Cells.Count = 1 Then
    If Trim(Target.Value) = ChrW("&h" & "00FC") Then
        Target.Value = ""
    ElseIf Trim(Target.Value) = "" Then
        Call Insert_Symbol_In_This_Cell(Target.Address, "00FC", "Wingdings")
    Else:
    End If
End If
End Sub
 
Last edited:
Upvote 0
I like green checkmarks myself, but you can change the color from the RGB (obviously).

And I find that if you would use right click instead of left click, it's better because you can right click on the same cell twice in a row and it will toggle the checkmark without any issue:
VBA Code:
Private Sub Worksheet_BeforeRightClick(ByVal Target As Range, Cancel As Boolean)
If Target.Cells.Count = 1 Then
    If Trim(Target.Value) = ChrW("&h" & "00FC") Then
        Cancel = True
        Target.Value = ""
    ElseIf Trim(Target.Value) = "" Then
        Cancel = True
        Call Insert_Symbol_In_This_Cell(Target.Address, "00FC", "Wingdings")
    Else:
    End If
End If
End Sub

But the choice is yours.
 
Upvote 0
But another option is to have left click, but have it move to a cell down (or over, if you change Target.Offset(1,0).Select to Target.Offset(0,1).Select) from the one you just selected. This way, you can toggle without any issues . . . except that the selected cell will no longer be the active cell by the end of the sub:
VBA Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Target.Cells.Count = 1 Then
    If Trim(Target.Value) = ChrW("&h" & "00FC") Then
        Target.Value = ""
        Application.EnableEvents = False
        Target.Offset(1, 0).Select
        Application.EnableEvents = True
    ElseIf Trim(Target.Value) = "" Then
        Call Insert_Symbol_In_This_Cell(Target.Address, "00FC", "Wingdings")
        Application.EnableEvents = False
        Target.Offset(1, 0).Select
        Application.EnableEvents = True
    Else:
    End If
End If
End Sub
 
Upvote 0
I like green checkmarks myself, but you can change the color from the RGB (obviously).

And I find that if you would use right click instead of left click, it's better because you can right click on the same cell twice in a row and it will toggle the checkmark without any issue:
VBA Code:
Private Sub Worksheet_BeforeRightClick(ByVal Target As Range, Cancel As Boolean)
If Target.Cells.Count = 1 Then
    If Trim(Target.Value) = ChrW("&h" & "00FC") Then
        Cancel = True
        Target.Value = ""
    ElseIf Trim(Target.Value) = "" Then
        Cancel = True
        Call Insert_Symbol_In_This_Cell(Target.Address, "00FC", "Wingdings")
    Else:
    End If
End If
End Sub

But the choice is yours.
I like this one better. I replaced the first code with this and it works great! Thanks again.
 
Upvote 0

Forum statistics

Threads
1,223,627
Messages
6,173,420
Members
452,514
Latest member
cjkelly15

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top