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
 

Excel Facts

How to create a cell-sized chart?
Tiny charts, called Sparklines, were added to Excel 2010. Look for Sparklines on the Insert tab.
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
 
Upvote 0
(y)
Thanks for the feedback
 
Upvote 0
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
 
Upvote 0
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
 
Upvote 0

Forum statistics

Threads
1,213,527
Messages
6,114,140
Members
448,551
Latest member
Sienna de Souza

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