I have a small macro that highlights an entire row in red if the cell value in J column contains the value 427.See below...
Dim lr As Long
lr = Worksheets("owssvr").Cells.Find("*", Cells(1, 1), xlFormulas, xlPart, xlByRows, xlPrevious, False).Row
Dim cell As Range
For Each cell In Range("J2:J" & lr)
If cell.Value = 427 Then
cell.EntireRow.Interior.Color = 255
End If
What I would like to do is to amend the macro so that it only highlights in red the section of the row that contains data, rather than the entire row (in this tables case, up to column AF). Thank you.
If you only want to highlight row between columns A
& F
then try-
Sub Highlight()
Dim lr As Long
lr = Worksheets("owssvr").Cells.Find("*", Cells(1, 1), xlFormulas, xlPart, xlByRows, xlPrevious, False).Row
Dim cel As Range
For Each cel In Range("J2:J" & lr)
If cel.Value = 427 Then
Range("A" & lr & ":F" & lr).Interior.Color = 255
End If
Next
End Sub
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.