Highlight Code

Papi

Well-known Member
Joined
May 22, 2007
Messages
1,592
Below is some code that I have been using for some time. The way it is written is that it sends the cursor to column A each time the code is ran. What can be done so that when the code is ran that the cursor remains where it is?

Option Explicit

Dim Rng As Range

Sub HighlightYellow()

Range("A" & ActiveCell.Row).Select

Set Rng = ActiveCell.Range("A1:Z1")

With Rng.Interior
.Pattern = xlSolid
.PatternColorIndex = xlAutomatic
.Color = 65535
.TintAndShade = 0
.PatternTintAndShade = 0
End With

Application.OnTime Now + TimeValue("00:00:10"), "RemoveHighlight"

End Sub

Sub RemoveHighlight()

With Rng.Interior
.Pattern = xlNone
.TintAndShade = 0
.PatternTintAndShade = 0
End With

End Sub
 

Excel Facts

Pivot Table Drill Down
Double-click any number in a pivot table to create a new report showing all detail rows that make up that number
Maybe this

Code:
Option Explicit
Dim rng As Range
 
Sub HighlightYellow()
    
    Set rng = Range("A" & ActiveCell.Row & ":Z" & ActiveCell.Row)
 
    With rng.Interior
        .Pattern = xlSolid
        .PatternColorIndex = xlAutomatic
        .Color = 65535
        .TintAndShade = 0
        .PatternTintAndShade = 0
    End With
 
    Application.OnTime Now + TimeValue("00:00:10"), "RemoveHighlight"
 
End Sub
 
Sub RemoveHighlight()
    
    With rng.Interior
        .Pattern = xlNone
        .TintAndShade = 0
        .PatternTintAndShade = 0
    End With
 
End Sub

HTH

M.
 
Upvote 0
Try changing the first sub to

Code:
Sub HighlightYellow()
    Set Rng = ActiveCell.EntireRow.Range("A1:Z1")
 
    With Rng.Interior
        .Pattern = xlSolid
        .PatternColorIndex = xlAutomatic
        .Color = 65535
        .TintAndShade = 0
        .PatternTintAndShade = 0
    End With
 
    Application.OnTime Now + TimeValue("00:00:10"), "RemoveHighlight"
End Sub
 
Upvote 0
Thanks very much to both Marcelo Branco and shg as both solutions work fine.

One further question, I have two conditions set in conditional formatting and they override this code. Is there some way that the highlight macro can override the two conditions and highlight instead?
 
Upvote 0
You would have to delete the conditional formatting and then reapply it.
 
Upvote 0
Thanks shg. Would that be possible by adding that to the highlight code to remove current conditions for only that row, apply the highlight and when done re-apply the condition in the same code?
 
Upvote 0
Thanks very much to both Marcelo Branco and shg as both solutions work fine.

One further question, I have two conditions set in conditional formatting and they override this code. Is there some way that the highlight macro can override the two conditions and highlight instead?

You are welcome.

shg has already answered your question.

M.
 
Upvote 0
Deleting the conditional formatting is easy.

To restore it, you need to reapply it in code, or copy it from somewhere else.

Why not just apply some formatting that isn't use by the conditional formatting, like borders?
 
Upvote 0
Thanks again. I will attempt to turn the condition off and back on. The worst case scenario is that it does not work. Running something on a copy of such a file just means I will not disapoint myself when I mess it up.

Thanks to both of you for all your help.
 
Upvote 0

Forum statistics

Threads
1,224,507
Messages
6,179,181
Members
452,893
Latest member
denay

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