Cell background colour changes when another cell is selected

fireslguk

Active Member
Joined
Nov 11, 2005
Messages
298
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

What does custom number format of ;;; mean?
Three semi-colons will hide the value in the cell. Although most people use white font instead.
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,215,761
Messages
6,126,735
Members
449,333
Latest member
Adiadidas

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