VBA Colored Rows (Conditional Formatting

Livin404

Well-known Member
Joined
Jan 7, 2019
Messages
743
Office Version
  1. 365
  2. 2019
Platform
  1. Windows
Greetings, I came up with a VBA Code that works precisely as I would like it to. However, I have three columns and a few do not have any data at all. It is those I like to have a supplemental statement put into my VBA where the Rows that have no data any any of the three columns on the same row will not be filled. Some rows I have data in column A and no data in Column C; those are fine. It's when there is no data at all in any of the three Columns I don't want the cell filled. Thank you,

VBA Code:
Sub Format_FID_ROWS()
Dim i, Count As Long
Dim wsAct As Worksheet
  
  Set wsAct = ActiveSheet
  Application.ScreenUpdating = False
  With Sheets("Inbound FIDS")
    .Activate
i = 1
Count = Sheets("Inbound FIDS").Cells(Rows.Count, "A").End(xlUp).Row

Do While i <= Count

Range(Cells(i, 1), Cells(i, 3)).Interior.Color = RGB(45, 45, 185)
i = i + 1

If i > Count Then
Exit Do
End If
Range(Cells(i, 1), Cells(i, 3)).Interior.Color = RGB(34, 34, 147)
i = i + 1

Loop
End With
wsAct.Activate
  Application.ScreenUpdating = True
End Sub
 

Excel Facts

Spell Check in Excel
Press F7 to start spell check in Excel. Be careful, by default, Excel does not check Capitalized Werds (whoops)
I added a quick check before formatting to see if all three columns are blank using

VBA Code:
If Cells(i, 1) = "" And Cells(i, 2) = "" And Cells(i, 3) = "" Then

You can see it in the code below. Try this:

VBA Code:
Sub Format_FID_ROWS()

Dim i, Count As Long
Dim wsAct As Worksheet
  
  Set wsAct = ActiveSheet
  Application.ScreenUpdating = False
  With Sheets("Inbound FIDS")
    .Activate
i = 1
Count = Sheets("Inbound FIDS").Cells(Rows.Count, "A").End(xlUp).Row

Do While i <= Count
    If Cells(i, 1) = "" And Cells(i, 2) = "" And Cells(i, 3) = "" Then
    
    Else
        Range(Cells(i, 1), Cells(i, 3)).Interior.Color = RGB(45, 45, 185)
    End If
    
    i = i + 1
        
    If i > Count Then
        Exit Do
    End If

    If Cells(i, 1) = "" And Cells(i, 2) = "" And Cells(i, 3) = "" Then
    
    Else
        Range(Cells(i, 1), Cells(i, 3)).Interior.Color = RGB(34, 34, 147)
    End If
    
    i = i + 1
Loop
End With
wsAct.Activate
  Application.ScreenUpdating = True
End Sub
 
Upvote 0
Solution

Forum statistics

Threads
1,215,722
Messages
6,126,464
Members
449,315
Latest member
misterzim

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