If you find any post useful then, please do share with others. Thanks!

Popular Posts

Contact

Email me

Need help and that also free? I like to learn this way, in case of any question or for a small task, please feel free to email me with details and example data, if required.

Thursday, October 31, 2013

Highlight Row of Selected Cell using VBA

Highlight Row of Selected Cell using VBA

While we are working in a big table of data and comparing with some other data or source, if the selected cell’s row gets highlighted then this can definitely help us in comparing and getting a sense.

Suppose our data is in the range B4:I14. Outside our range somewhere like the cell E17, let us name it as selRow. This is for keeping the details that which row to highlight.

Right click on the sheet name and choose the option of view code. Write the below code there.
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    [selRow] = Target.Row
   
End Sub

The next step is to add conditional formatting to highlight selected cell’s row. For this select the entire range (B4:I14) and go to conditional formatting and new rule. Here select the rule type as Use a Formula and use the below rule and use your color formatting.
=ROW(B4) = selRow

It’s done now when you click in a cell of the range the whole row will get highlighted. Please experiment it and let me know in case of any issue.


No comments:

Post a Comment