Error Trying To Change The Font Color Of A Range

Ark68

Well-known Member
Joined
Mar 23, 2004
Messages
4,538
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
I don't understand why I am receiving an 'application-defined or object defined error" with the line highlighted in the code below:

Rich (BB code):
    With wshmain
        
        If .Range("K46") = "NR" Then
            .Range("L46, L48") = "NR"
            .Range("K47, K49, K48, K46") = ""
            .Range("K46:N49").Font.Color = RGB(224, 224, 224)
            .Range("L46:N46, K47:M47, L48:N48, K49:M49").MergeCells = True
            .Range("L46,K47,K48,L48,K49").Locked = True
            .Protect
            Exit Sub
        End If
 

Excel Facts

Test for Multiple Conditions in IF?
Use AND(test, test, test, test) or OR(test, test, test, ...) as the logical_test argument of IF.
Note that if you have already run the code once, or otherwise protected/merged some cells, you will probably need to unprotect and unmerge them your sheet at the beginning of the code for those commands to run without errors!

Also, I think your "locked" statement will work better if you match the range above from the MergeCell statement, i.e.
Code:
            .Range("L46:N46, K47:M47, L48:N48, K49:M49").MergeCells = True
            .Range("L46:N46, K47:M47, L48:N48, K49:M49").Locked = True
 
Upvote 0

Forum statistics

Threads
1,202,990
Messages
6,052,952
Members
444,621
Latest member
MIKOLAJ_R

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