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

Why are there 1,048,576 rows in Excel?
The Excel team increased the size of the grid in 2007. There are 2^20 rows and 2^14 columns for a total of 17 billion cells.
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,246
Messages
6,170,996
Members
452,373
Latest member
TimReeks

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