change the background's color for current cell

  • Thread starter Thread starter moshe_xls
  • Start date Start date
M

moshe_xls

I'm looking for a macro that marks the current cell in worksheet. It has to
be a dynamic function (for any move the current cell will be mark). I want
that the cell will be colored.
Is there a built-in option for that? If yes how can I defined it?
 
Hi
Put this code in the code module behind the sheet where you want to
colour cells.

Option Explicit
Dim lastCell As Range

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Target.Interior.ColorIndex = 6
On Error Resume Next
lastCell.Interior.ColorIndex = xlColorIndexNone
Set lastCell = Target
End Sub

(To see this code module, open the visual basic editor, identify the
sheet in the explorer pane and double click it)

regards
Paul
 
Thank you Paul for your replay,

I insert the code as a macro and didn't get anything – how can I make it run?
My be I didn't make my self clear - I want this program to be run
automatically for any cell I will chose (I couldn't understand if it's in the
code).

Best regards,
Moshe
 
Hi
It will run each time you select a cell.
Did you put the macro in the right place? It does NOT go into a
general code module, it goes into the code module behind the
particular sheet you will be selecting cells in. As I said, to see
this code module open the visual basic editor, identify the sheet in
the explorer pane (e.g. sheet1) and double click it.
regards
Paul
 
Thanks its work beautifully :-)

Hi
It will run each time you select a cell.
Did you put the macro in the right place? It does NOT go into a
general code module, it goes into the code module behind the
particular sheet you will be selecting cells in. As I said, to see
this code module open the visual basic editor, identify the sheet in
the explorer pane (e.g. sheet1) and double click it.
regards
Paul
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top