It will, but I would be very wary about using it as it will also
remove all existing formatting (cell colour either direct or Conditional Formatting, borders, text colour, bolding etc) from Sheet1. Further, without explanation this code may be applied to a sheet other than Sheet1 so that formatting destruction may even be on another worksheet. In that instance the sheet this is applied to will continually build up yellow colour in many rows/columns.
Yes it is and I prefer the Conditional formatting approach as it will not destroy any existing colour in the worksheet. Another advantage is that if the worksheet already has conditional formatting, this new CF will temporarily over-ride it so the selected row/column is clearly visible. (If other CF is added
after the CF described here, it may hinder this & a slight adjustment could be needed. Post back if further information about this is required)
1. Select the whole worksheet (by clicking the box at the top left at the intersection of the column labels and row labels). We could select a lesser range but applying it to the whole worksheet doesn't seem to make files too big or slow in my experience.
2. Use Conditional Formatting -> New rule.. -> Use a formula to determine ... -> Format values where this formula is true: =CELL("row")=ROW() -> Format... -> On the Fill tab select the colour you want** for the entire row -> Ok -> Ok
3. With the whole sheet still selected go to Conditional Formatting -> New rule.. -> Use a formula to determine ... -> Format values where this formula is true: =CELL("col")=COLUMN() -> Format... -> On the Fill tab select the same colour -> Ok -> Ok
4. Right click the sheet name tab and choose 'View Code'
5. Copy and Paste the code below into the main right hand pane that opens at step 4.
6. Close the Visual Basic window & test.
Rich (BB code):
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Application.ScreenUpdating = True
End Sub
** When choosing a colour, better to choose a colour that is not already used on the worksheet. On the Fill tab if you go to 'More Colors...' it would be easy to make a colour unique for your sheet.
A further advantage of this method it that even with the vba code involved, Excel's 'Undo' function is preserved.