Highlight the selected cell.

User avatar
adam
SilverLounger
Posts: 2347
Joined: 23 Feb 2010, 12:07

Highlight the selected cell.

Post by adam »

Hi anyone,

How could the following code made to highlight the selected cell instead of C67 only?

Code: Select all

Sub Highlight() 
    Range("C67").Select 
    With Selection.Interior 
        .Pattern = xlSolid 
        .PatternColorIndex = xlAutomatic 
        .Color = vbYellow 
        .TintAndShade = 0 
        .PatternTintAndShade = 0 
    End With 
End Sub 
Any help on this would be kindly appreciated.
Best Regards,
Adam

User avatar
HansV
Administrator
Posts: 78542
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Highlight the selected cell.

Post by HansV »

Remove the line

Range("C67").Select
Best wishes,
Hans

User avatar
adam
SilverLounger
Posts: 2347
Joined: 23 Feb 2010, 12:07

Re: Highlight the selected cell.

Post by adam »

Thanks for the help Hans. The code works fine how could the thick border that appears by default around the selected cell be removed?
Best Regards,
Adam

User avatar
HansV
Administrator
Posts: 78542
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Highlight the selected cell.

Post by HansV »

You can't change that.
Best wishes,
Hans

User avatar
adam
SilverLounger
Posts: 2347
Joined: 23 Feb 2010, 12:07

Re: Highlight the selected cell.

Post by adam »

How could the code be made as a worksheet event code so that the selected cell gets highlighted automatically.
Best Regards,
Adam

User avatar
HansV
Administrator
Posts: 78542
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Highlight the selected cell.

Post by HansV »

That's tricky, I wouldn't do that. You'd have to keep track of which cell is selected and you might easily end up with incorrectly highlighted cells.

But if you want something similar, look at Chip Pearson's RowLiner Add-In or Jan Karel Pieterse's Follow Cell Pointer add-in in JKP-ADS Download page (both are free).
Best wishes,
Hans

User avatar
adam
SilverLounger
Posts: 2347
Joined: 23 Feb 2010, 12:07

Re: Highlight the selected cell.

Post by adam »

Thanks for the help Hans. I do really appreciate your help.
Best Regards,
Adam