modify current VBA from cell to row

BCsehi

New Member
Joined
Jan 20, 2011
Messages
31
Here is the code I am using to highlight the active cell in Excel and then keeping the original formatting:

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Static oPrev As Range

On Error Resume Next
oPrev.FormatConditions.Delete
Target.FormatConditions.Add(Type:=xlExpression, Formula1:=True).Interior.Color = vbRed
Set oPrev = Target
End Sub

I want to change this from just highlighting the active cell to the active row. Can someone help me with this? As you've probably guessed, I am not w VBA user! Thanks!
 

Excel Facts

Ambidextrous Undo
Undo last command with Ctrl+Z or Alt+Backspace. If you use the Undo icon in the QAT, open the drop-down arrow to undo up to 100 steps.
I'm more adept at Access vba. Sometimes when I want to figure out something in Excel vba I use the macro recorder and adapt the results. Or I Google something (like in this case, "Excel vba highlight row". Just saying, because I actually don't have code for this but presume it would be to refer to Target.Row. However, I don't see how what you have works because you don't SET the range variable to anything. I do see why you're not aware of any issue that would arise from that, and that's because of Resume Next statement.
 
Upvote 0
10 minutes of searching and a simple test and this seems to do what you're asking for:
Target.EntireRow.Interior.ColorIndex = 37

It's probably not what you really want though. Highlighting the row will go right to the very end column.
 
Upvote 0
10 minutes of searching and a simple test and this seems to do what you're asking for:
Target.EntireRow.Interior.ColorIndex = 37

It's probably not what you really want though. Highlighting the row will go right to the very end column.
could you please tell me where I put this (your suggestion) within the code that I am currently using? It sounds like exactly what I want....
 
Upvote 0
maybe right after this line: Static oPrev As Range

which as I said, makes no sense to me, nor does the Resume Next. If you have no clue about vba as you've indicated then perhaps you ought to research those 2 topics:
Declaring object variables
and
On Error statement
to see if they fit your requirements as you've used them.
 
Upvote 0
maybe right after this line: Static oPrev As Range

which as I said, makes no sense to me, nor does the Resume Next. If you have no clue about vba as you've indicated then perhaps you ought to research those 2 topics:
Declaring object variables
and
On Error statement
to see if they fit your requirements as you've used them.
Not what I'm looking for. The code that I have in place now, highlights the "active cell" and then when I go to another "active cell", the former "active cell" reverts back to its original format and the new "active cell" is highlighted. All I want to change is from "active cell" to "active row". Thanks for trying to help, it is much appreciated.
 
Upvote 0
So you want the code to highlight the active row but remove interior colour of whatever row had been previously coloured by this code? I only glanced through the suggested link so not sure if it will help you or not. Will wait to find out.
 
Upvote 0
So you want the code to highlight the active row but remove interior colour of whatever row had been previously coloured by this code? I only glanced through the suggested link so not sure if it will help you or not. Will wait to find out.
Yes, but when a new cell is active, the former reverts to all of its previous formatting.
 
Upvote 0
I've only glanced at this thread but does this update to your posted code does what you want

VBA Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    Cells.FormatConditions.Delete
    Target.EntireRow.FormatConditions.Add(Type:=xlExpression, Formula1:=True).Interior.Color = vbRed
End Sub

change assumes that you have no other CF on the sheet

Dave
 
Upvote 0

Forum statistics

Threads
1,215,043
Messages
6,122,816
Members
449,095
Latest member
m_smith_solihull

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