Cell background colour changes when another cell is selected

fireslguk

Active Member
Joined
Nov 11, 2005
Messages
305
hi i had some code but cannot find anymore


can someone help on this:-


c3:c1000 has a cream background colour and will sometimes have data entered

when the cursor is moved up and down G column i would like the corresponding row in column C to highlight


purpose so can identify the correct row being used
 

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 do this on one of my sheets.

You need to remember the previous row by recording it every time the selection changes. So you can reset it. This is basic but works for highlighting selected row to red

Make sure the lPrev is declared at the top of the module

Code:
Dim lPrev As Long


Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    If Target.Cells.Count = 1 Then Target.EntireRow.Interior.Color = vbRed
    If lPrev > 0 And lPrev <> Target.Row Then Rows(lPrev).Interior.Color = xlNone
    lPrev = Target.Row
End Sub
 
Upvote 0
Another option
Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
   Static Rw As Long
   If Target.CountLarge > 1 Then Exit Sub
   If Not Intersect(Target, Range("G3:G1000")) Is Nothing Then
      If Rw > 0 Then Range("C" & Rw).Interior.Color = [COLOR=#ff0000]6737151[/COLOR]
      Rw = Target.Row
      Range("C" & Rw).Interior.Color = [COLOR=#ff0000]567890[/COLOR]
   End If
End Sub
Change values in red to match the colours you want
 
Upvote 0
Copy and paste this macro into the worksheet code module. Do the following: right click the tab name for your sheet and click 'View Code'. Paste the macro into the empty code window that opens up. Change the color index (in red) to suit your needs. Close the code window to return to your sheet. Click on any cell in G3:G1000.
Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    If Intersect(Target, Range("G:G")) Is Nothing Then Exit Sub
    Range("C3:C1000").Interior.ColorIndex = [COLOR="#FF0000"]36[/COLOR]
    Range("C" & Target.Row).Interior.ColorIndex = 3
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,170
Members
453,021
Latest member
Justyna P

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