PDA

View Full Version : Highlight the selected cell



uktous
10-19-2012, 08:21 AM
Hi,

I created a macro that can highlight the selected cell.

However, my macro will clear the colour in all cell before it highlights the selected cell.

Is it possible to amend it so that it will clear the colour in the previous selected cell only, rather than clearing colour in all cells?

I want the macro that has this feature:

Clear the colour in previous selected cell only, then highlight the current selected cell.




Private Sub Worksheet_SelectionChange(ByVal Target As Range)

Set x = Selection

Cells.Interior.ColorIndex = xlNone

x.Interior.Color = 65535


End Sub








Thanks

patel
10-19-2012, 08:46 AM
Dim OldCell As String
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
On Error Resume Next
Range(OldCell).Interior.ColorIndex = 0
Target.Interior.Color = vbRed 'QBColor(10)
OldCell = Target.Address
End Sub

uktous
10-21-2012, 07:32 PM
Dim OldCell As String
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
On Error Resume Next
Range(OldCell).Interior.ColorIndex = 0
Target.Interior.Color = vbRed 'QBColor(10)
OldCell = Target.Address
End Sub

Hi,

Your macro does work.

However, there is another problem that I can not resolve.

If I used this macro, I am unable to do copy and paste.

For example, I can not copy the data from cell A1 and then paste to cell B1.\

I have added Application.CutCopyMode = true, but was not helpful.

Could you please resolve that?

Thanks