Error Trying To Change The Text Color In A Cell (VBA)

Ark68

Well-known Member
Joined
Mar 23, 2004
Messages
4,564
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
Consider this piece of code...
Rich (BB code):
    If Not Application.Intersect(KeyCells, Range(Target.Address)) Is Nothing Then
        'check for valid date
        If IsDate(KeyCells.Value) = False Then
            mbevents = False
            ws_master.Range("M1").Value = "Enter valid date (month/day)"
            ws_master.Range("M1").Font.Color = RGB(192, 57, 43)
            mbevents = True
        End If
        Exit Sub
    End If

The line highlighted in red is giving me an error: "Application-defined or object defined error".

Is anyone able to isolate the problem and suggest a resolution.

Note, the worksheet is protected, but the cell is unlocked (there are no issues with applying the value to the same cell). Cell M1 is a merged cell, but even when I try to unmerge I get the same error.
Code:
ws_master.Range("M1").unmerge
 

Excel Facts

Is there a shortcut key for strikethrough?
Ctrl+S is used for Save. Ctrl+5 is used for Strikethrough. Why Ctrl+5? When you use hashmarks to count |||| is 4, strike through to mean 5.
Yet another reason not to use the abomination that is merged cells.
You will need to unprotect the sheet.
 
Upvote 0
Thanks Fluff, I have learned that the better option to avoid merging cells is to use the centeracrossselection horizontal alignment.
But in this case, I am merged both vertically and horizontally. Is there a way I can combine a range M1:Q2 without merging?
 
Upvote 0
Not that I'm aware of.
 
Upvote 0
Thanks Fluff ... objective achieved. I appreciate your help!
 
Upvote 0
Glad you sorted it & thanks for the feedback.
 
Upvote 0
If you allow formatting cells when you protect the sheet, you shouldn't have to unprotect to change the font colour in an unlocked cell.
 
Upvote 0

Forum statistics

Threads
1,214,943
Messages
6,122,380
Members
449,080
Latest member
Armadillos

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