Conditional formatting using VBA

flemming94

New Member
Joined
Aug 1, 2017
Messages
3
Thanks to security settings on a file at work, I can't use conditional formatting, but I can use macro's (I know, kinda stupid). So I'd like to make an easy macro to make empty cells red in a specific column (A7 through A100). I'm kinda new to the VBA project and can't figure it out. Can someone help me?
 

Excel Facts

Save Often
If you start asking yourself if now is a good time to save your Excel workbook, the answer is Yes
Welcome to the board.

something like this
Code:
Sub ColorBlanks()
Dim c As Range
For Each c In Range("A7:A100")
    If c.Value = "" Then
        c.Interior.Color = vbred
    Else
        c.Interior.ColorIndex = xlnone
    End if
Next c
End Sub
 
Last edited:
Upvote 0
Many thanks

It seems it works in an unprotected sheet, but not in the protected one... Seems like they checked an extra option so no lay out can be changed.
 
Upvote 0
You can unprotect the sheet, run the code, then reportect the sheet..

Rich (BB code):
Sub ColorBlanks()
Dim c As Range
ActiveSheet.Unprotect "passwordgoeshere"
For Each c In Range("A7:A100")
    If c.Value = "" Then
        c.Interior.Color = vbred
    Else
        c.Interior.ColorIndex = xlnone
    End if
Next c
ActiveSheet.Protect "passwordgoeshere"
End Sub
 
Upvote 0
Problem is that it's an official document from work and I don't know the password (and I'm not supposed to know) But I can certainly use this on other projects. Thanks!
 
Upvote 0

Forum statistics

Threads
1,223,912
Messages
6,175,340
Members
452,638
Latest member
Oluwabukunmi

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