Forum

Sub Routine not wor...
 
Notifications
Clear all

Sub Routine not working inside Sheet

2 Posts
2 Users
0 Reactions
90 Views
(@kwesmc1)
Posts: 31
Trusted Member
Topic starter
 

So sorry. I originally posted this on the wrong category.

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

 

</> Option Explicit 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 ' If UCase(cell.Value) Like "*MEDIUM*" Then cell.Font.Color = vbRed Next cell End Sub </>

 
Posted : 12/04/2018 10:38 am
(@sunnykow)
Posts: 1417
Noble Member
 

Hi Kenneth

Most likely you place the codes in the wrong module.

In your case (auto format when cell change) the codes should be place in the worksheet module.

Please refer my example. It uses range A1:A10 as an example.

You can refer here for more details :  https://www.myonlinetraininghub.com/workbook-worksheet-events-excel-vba

Hope this helps.

Sunny

 
Posted : 14/04/2018 10:10 pm
Share: