I want to highlight some cells in my worksheet. My worksheet may have >1 table, with empty rows or title between the tables.
Example
1 10 100
15 59 200
title1
1 10 100
15 59 200
I tried the below code, but only the cells in the 1st column get highlighted.
Thank you.
Sub SmallSample()
Dim SourceSht As Worksheet
Dim rngCopy As Range
Dim LastCopyRow As Long
Dim LastCopyColumn As Long
Dim x As Integer
Set SourceSht = ThisWorkbook.Worksheets("Sheet1")
LastCopyRow = SourceSht.Cells(Rows.Count, "A").End(xlUp).Row
LastCopyColumn = SourceSht.Cells(1, Columns.Count).End(xlToLeft).Column
Set rngCopy = SourceSht.Range("A3:" & SourceSht.Cells(LastCopyRow, LastCopyColumn).Address)
For Each x In rngCopy
If x.Value >= 10 And x.Value < 50 Then
x.Interior.Color = RGB(183, 222, 232)
ElseIf x.Value <> "" And x.Value < 10 Then
x.Interior.Color = RGB(255, 255, 0)
End If
Next x
End Sub
Example
1 10 100
15 59 200
title1
1 10 100
15 59 200
I tried the below code, but only the cells in the 1st column get highlighted.
Thank you.
Sub SmallSample()
Dim SourceSht As Worksheet
Dim rngCopy As Range
Dim LastCopyRow As Long
Dim LastCopyColumn As Long
Dim x As Integer
Set SourceSht = ThisWorkbook.Worksheets("Sheet1")
LastCopyRow = SourceSht.Cells(Rows.Count, "A").End(xlUp).Row
LastCopyColumn = SourceSht.Cells(1, Columns.Count).End(xlToLeft).Column
Set rngCopy = SourceSht.Range("A3:" & SourceSht.Cells(LastCopyRow, LastCopyColumn).Address)
For Each x In rngCopy
If x.Value >= 10 And x.Value < 50 Then
x.Interior.Color = RGB(183, 222, 232)
ElseIf x.Value <> "" And x.Value < 10 Then
x.Interior.Color = RGB(255, 255, 0)
End If
Next x
End Sub