Aug 26 2021 06:17 AM - edited Aug 26 2021 06:28 AM
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..
Aug 26 2021 07:10 AM
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
Aug 26 2021 07:14 AM
Aug 26 2021 07:42 AM
Aug 26 2021 07:43 AM
Aug 26 2021 08:37 AM
SolutionChange 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.
Aug 26 2021 08:39 AM
Aug 26 2021 08:37 AM
SolutionChange 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.