VBA-Macro/range based on font name

Starstopper31

New Member
Joined
Jan 19, 2015
Messages
8
I am fairly new to macros/VBA, although I am learning enough to be dangerous. I currently am using the code listed below to create checkboxes when the user clicks a cell within the defined range. I set the font of each cell within the range to "Wingdings", and when the user clicks on the cell, a check appears in the cell. It works well, but the actual document I have has several different areas where a checkbox will be needed. On top of that, there is a possibility that the form will become dynamic, so I am trying to avoid having a specific range where the code is applied. I would prefer to have the code work for all cells within the sheet where "Wingdings" is the font. Is something like that possible? Can someone offer me a suggestion for how I could alter it? I have been trying on and off for a few days and I keep getting errors. Any help would be appreciated. Thanks!

VBA Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Excel.Range)
  Application.EnableEvents = False
  If Target.Cells.Count = 1 Then
    If Not Intersect(Target, Range("A1:A10")) Is Nothing Then
      Select Case Target.Value
      Case ""
        Target.Value = "ü"
      Case "+"
        Target.Value = ""
      Case Else
        Target.Value = ""
      End Select
    End If
  End If
  Application.EnableEvents = True
End Sub
 

Excel Facts

What does custom number format of ;;; mean?
Three semi-colons will hide the value in the cell. Although most people use white font instead.
How about
VBA Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Excel.Range)
  Application.EnableEvents = False
  If Target.CountLarge = 1 Then
    If Target.Font.Name = "Wingdings" Then
      Select Case Target.Value
      Case ""
        Target.Value = "ü"
      Case "+"
        Target.Value = ""
      Case Else
        Target.Value = ""
      End Select
    End If
  End If
  Application.EnableEvents = True
End Sub
 
Upvote 0
Solution
How about
VBA Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Excel.Range)
  Application.EnableEvents = False
  If Target.CountLarge = 1 Then
    If Target.Font.Name = "Wingdings" Then
      Select Case Target.Value
      Case ""
        Target.Value = "ü"
      Case "+"
        Target.Value = ""
      Case Else
        Target.Value = ""
      End Select
    End If
  End If
  Application.EnableEvents = True
End Sub
 
Upvote 0
How about
VBA Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Excel.Range)
  Application.EnableEvents = False
  If Target.CountLarge = 1 Then
    If Target.Font.Name = "Wingdings" Then
      Select Case Target.Value
      Case ""
        Target.Value = "ü"
      Case "+"
        Target.Value = ""
      Case Else
        Target.Value = ""
      End Select
    End If
  End If
  Application.EnableEvents = True
End Sub
Thank you, that worked great. I feel like I tried something similar, but I must have had a typo or something. Thanks for the help!
 
Upvote 0
You're welcome & thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,214,891
Messages
6,122,105
Members
449,066
Latest member
Andyg666

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