Sub Routine not working inside Sheet

kwesmc

Board Regular
Joined
Jan 25, 2008
Messages
83
I have as simple module which changes the font based on the name I select inside my worksheet. The code works well when I'm in the VBE and press F5, but when I'm in the worksheet and select a choice in the cell like "YES", the font reverts back to the default font. I know I'm doing something stupid with my code, but can't figure out what. Can someone help please? See code below.
Thanks so much!
Ken Mc

Code:
Sub test()
Dim cell As Object

For Each cell In Range("B2:M35")
If UCase(cell.Value) Like "*YES*" Or UCase(cell.Value) Like "*MODERATE*" Then
cell.Font.Name = "Comic Sans MS"
cell.Font.Bold = True
End If

Next cell

End Sub
 

Excel Facts

Convert text numbers to real numbers
Select a column containing text numbers. Press Alt+D E F to quickly convert text to numbers. Faster than "Convert to Number"
Ken

How are you executing the code from the sheet?
 
Upvote 0
I can create a button, but what I was wondering if there was anyway to make the code change the font after input into a cell?
 
Upvote 0
How about
Code:
Private Sub Worksheet_Change(ByVal Target As Range)

   If Target.CountLarge > 1 Then Exit Sub
   If Intersect(Target, Range("B2:M35")) Is Nothing Then Exit Sub
Application.EnableEvents = False
   If UCase(Target.Value) Like "*YES*" Or UCase(Target.Value) Like "*MODERATE*" Then
      Target.Font.Name = "Comic Sans MS"
      Target.Font.bold = True
   End If
Application.EnableEvents = True

End Sub
This needs to go in the relevant sheet module
 
Upvote 0
Thank you very much Fluff!! Works great.
You are a champ!!

Thank you very much!
Ken Mc
 
Upvote 0
Glad we could help & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,215,767
Messages
6,126,774
Members
449,336
Latest member
p17tootie

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