How to change the cell fill color if cell is no longer blank?

antman2988

Board Regular
Joined
Jun 28, 2018
Messages
78
Hello,

I have a checkbox that changes the color of a cell if it is checked. The user can't print the page until a value is entered into the highlighted field. Both the checkbox and restrict printing modules are working properly.

How do I change the color of the highlighted field once the user enters a value? I wrote the below code, but it isn't working. I am newer to VBA so any help is appreciated!

Edit: The code works fine when I manually run it. How do I make sure it runs once a user enters a value?

Code:
[COLOR=#333333]Private Sub Can_Print()[/COLOR]

[COLOR=#333333]    If IsEmpty(Range("G54")) = False Then[/COLOR]

[COLOR=#333333]        MsgBox "You may now print."[/COLOR]
[COLOR=#333333]        Range("G54").Interior.Color = RGB(221, 235, 247)

    End If[/COLOR]

[COLOR=#333333]End Sub[/COLOR]
 
Last edited:

Excel Facts

When did Power Query debut in Excel?
Although it was an add-in in Excel 2010 & Excel 2013, Power Query became a part of Excel in 2016, in Data, Get & Transform Data.
How about
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
   If Target.CountLarge > 1 Then Exit Sub
   If Target.Address(0, 0) = "G54" And Target.Value <> "" Then
      Target.Interior.Color = RGB(221, 235, 247)
      MsgBox "You can print"
   End If
End Sub
This needs to go in the sheet module for that sheet
 
Upvote 0

Forum statistics

Threads
1,223,910
Messages
6,175,320
Members
452,635
Latest member
laura12345

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