Excel macro woes

Soldato
Joined
7 Mar 2011
Posts
6,859
Location
Oldham, Lancashire
Just a simple one I guess.

I am trying to write a macro that will change the background of the current row, and increase the value of a cell by 1. I have hit a stumbling block though as my code (below) actually colours the row a few lines down. And If it's not column A selected, the coloured cells will be shifted over.

What I want is to be able to select say any cell row 7, then A7:K7 will turn colour.

Code:
ActiveCell.Range("A" & ActiveCell.Row(), "K" & ActiveCell.Row()).Interior.ColorIndex = 8

Thanks guys.
 
Soldato
Joined
11 May 2014
Posts
5,472
Location
Edinburgh
This works:

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
With Target.Cells(1)
If .Row <> 7 Then Exit Sub
Range("A7:K7").Interior.ColorIndex = 8
End With
End Sub

Any cell in row 7 that gets selected colours your A7:K7 range.

just whack this under the sheet you want the change to happen on :)
 
Back
Top Bottom