TomTS/Dave - bit more help on permanent highlighting, plz

BenNV

Board Regular
Joined
Mar 27, 2002
Messages
160
Morning, I have the following piece of code that highlights rows depending on various conditions. This is an extension upon your recommendation of putting the code in Private Sub Worksheet_Calculate() to allow the process to run continuously without user interference.

The problem is the value in D1 is always moving and when the condition is met the row is highlighted but as soon as the value in D1 changes, the highlight clears - I don't want this. I want the highlight to remain. Can you help please? Here's the code:

Private Sub Worksheet_Calculate()

Dim lLastRow As Long, Data1, ColE, ColG, ColH, COlI, lRow As Long
Dim shtThis As Worksheet, bThisRow As Boolean
Data1 = Cells(1, 4).Value

Set shtThis = ActiveSheet

With Cells(5, 1).CurrentRegion
lLastRow = .Rows.Count + .Row - 1
End With

For lRow = 5 To lLastRow
ColE = Cells(lRow, 5).Value
ColG = Cells(lRow, 7).Value
ColH = Cells(lRow, :cool:.Value
COlI = Cells(lRow, 9).Value

bThisRow = False

Select Case ColG
Case "DNT"
If ColH = Data1 Or COlI = Data1 Then _
bThisRow = True
Case "OT"
If ColE = Data1 Then _
bThisRow = True
Case "RKO", "KO"
Select Case ColF
Case "C"
If COlI = Data1 Then _
bThisRow = True
Case "P"
If ColH = Data1 Then _
bThisRow = True
End Select
End Select

With shtThis.Rows(lRow)
If bThisRow Then
With .Interior
.ColorIndex = 3
.Pattern = xlSolid
End With
Else
With .Interior
.ColorIndex = xlNone
.Pattern = xlNone
End With
End If
End With

Next
 

Excel Facts

Enter current date or time
Ctrl+: enters current time. Ctrl+; enters current date. Use Ctrl+: Ctrl+; Enter for current date & time.
Sorry guys, ignore the last msg. Took the else statement off - all ok now.

Thanks anyway.
 
Upvote 0

Forum statistics

Threads
1,214,821
Messages
6,121,759
Members
449,048
Latest member
excelknuckles

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top