help needed for macro to colour a row by clicking on a cell in the row

Ratigan

New Member
Joined
Jul 21, 2013
Messages
36
hi everyone at mr excel
i have a worksheet with rows of info and im looking for a macro for when i click on a cell in column G in the row it will change the background colour to yellow from column B to J
sounds simple but i cant figure out
many thanks if someone could help me out
 

Some videos you may like

Excel Facts

Back into an answer in Excel
Use Data, What-If Analysis, Goal Seek to find the correct input cell value to reach a desired result

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
46,578
Office Version
  1. 365
Platform
  1. Windows
Hi
How about this?
Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)

    If Target.Column = 7 Then Target.Offset(0, -5).Resize(1, 9).Interior.ColorIndex = 6

End Sub
It needs to go in the sheet module
Right click on the sheet tab & select view code
 

Ratigan

New Member
Joined
Jul 21, 2013
Messages
36
thank you for your quick reply fluff, the code works well thank you.
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
46,578
Office Version
  1. 365
Platform
  1. Windows
(y)
Thanks for the feedback
 

Ratigan

New Member
Joined
Jul 21, 2013
Messages
36

ADVERTISEMENT

Hi Fluff sorry to be a pain.
the code is working well but sometimes i make a mistake and click on the wrong line and i have to undo what i have done. is it possable to mod the code so when i click it again it would clear the background colour ??
many thanks
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
46,578
Office Version
  1. 365
Platform
  1. Windows
Hiya
Try this
Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)

    If Target.Column = 7 Then
        With Target.Offset(0, -5).Resize(1, 9).Interior
            If Not .ColorIndex = 6 Then .ColorIndex = 6 Else .ColorIndex = xlNone
        End With
    End If

End Sub
 

Ratigan

New Member
Joined
Jul 21, 2013
Messages
36
many thanks Fluff just what i needed :pray::pray::pray:
keep up the good work
 

Watch MrExcel Video

Forum statistics

Threads
1,109,446
Messages
5,528,802
Members
409,836
Latest member
karnasrinivas
Top