Forum Discussion
Question related highlight cell with the help of VBA code
Hello Everyone,
I want to highlight cells(Red colour) which is more than 4 in SPACE COLUMN with the help of VBA code.
So, what should i write in VBA code?
Please help..??
Here is a attached..
Change the line
Range("A" & r).Resize(1, 4).Interior.Color = vbRed
to
Range("D" & r).Interior.Color = vbRed
Remark: if you want to learn to write VBA, you should really try to make such changes yourself. Even if you make mistakes, you will learn much more from experimenting than from asking us for every small detail.
6 Replies
- JKPieterseSilver ContributorWhy would you want to use VBA for this? A simple conditional format would suffice.
- ExcelIron ContributorHello Sir,
Actually i am learning VBA program.
You can easily use conditional formatting for this. You wouldn't need VBA, and the formatting would be updated automatically when the values in column D change.
But if you really want to use VBA:
Sub ColorCells() Dim r As Long Dim m As Long Application.ScreenUpdating = False m = Range("D" & Rows.Count).End(xlUp).Row Range("A2:D" & m).Interior.ColorIndex = xlColorIndexNone For r = 2 To m If Range("D" & r).Value > 4 Then Range("A" & r).Resize(1, 4).Interior.Color = vbRed End If Next r Application.ScreenUpdating = True End Sub
- ExcelIron ContributorSir, if we highlight only SPACE column, then what should i write in VBA?
Change the line
Range("A" & r).Resize(1, 4).Interior.Color = vbRed
to
Range("D" & r).Interior.Color = vbRed
Remark: if you want to learn to write VBA, you should really try to make such changes yourself. Even if you make mistakes, you will learn much more from experimenting than from asking us for every small detail.