Jira Courses, Training and Consulting: Sparxsys Trainings
Thanks for coming here, I hope you are enjoying learning here, I have also written some books in case you want to learn a bit more :)
If you need my help with Drupal, Linux, Jira, Scripting, Automation or want to contact me then raise a ticket for me please :) and I will get back to you, promise. At Sparxsys we provide Atlassian consultancy services, reach out to me at ravi at sparxsys dot com

How to change the background color of entire row in Excel using VBA code - Conditional

My friend Vinod gave me a problem to change the background color of entire row to Red and also to change the font to bold. It seems to be an easy task but there are two constraints.
1. He want to do this only for those lines which has font color of red.
2. There are 2500 entries in the excel.

Now if you have plenty of time then you can do this task in some hundred years :) but I am a Lazy guy so I wrote this little Macro code.

Private Sub Workbook_Open()
For Each cell In Worksheets("sheet1").Range(Worksheets("sheet1").Range("A1"), _
Worksheets("sheet1").Range("A1").End(xlDown))
        If cell.Font.Color = RGB(255, 0, 0) Then
            cell.Font.Color = RGB(0, 0, 0)
          cell.EntireRow.Font.Bold = True
          cell.EntireRow.Interior.Color = RGB(255, 0, 0)
        End If
       
    Next cell
End Sub

You can write this code either in the Open Event of the Workbook or write a Module for it.

For Each cell In Worksheets("sheet1").Range(Worksheets("sheet1").Range("A1"), Worksheets("sheet1").Range("A1").End(xlDown))

This code simply defines the range starting from cell A1 till the bottom most cell which has any data.

End(xlDown))
This is similar to pressing Ctrl + Down Arrow

cell.Font.Color = RGB(0, 0, 0)
This code changes the font color of the cell content

cell.EntireRow.Font.Bold = True
This code changes the font to Bold

cell.EntireRow.Interior.Color = RGB(255, 0, 0)
This code fills the cell with Red color

Similar posts

Subscribe

* indicates required

Please confirm that you would like to from Sparxsys:

You can unsubscribe at any time by clicking the link in the footer of our emails. For information about our privacy practices, please visit our website.

We use Mailchimp as our marketing platform. By clicking below to subscribe, you acknowledge that your information will be transferred to Mailchimp for processing. Learn more about Mailchimp's privacy practices.

Want to contact me?