highlighting last edited cell

Aamir khan

New Member
Joined
Feb 11, 2018
Messages
9
how can we highlight last edited cell e.g if i use A1 it will highlight after use and then i use B5 then highlighting remove from A1 and B5 will highlight
 
Try this:-
It's the same code but within a ChangeEvent Cover.

Code:
Option Explicit
[COLOR="Navy"]Dim[/COLOR] Rng [COLOR="Navy"]As[/COLOR] Range, temp [COLOR="Navy"]As[/COLOR] Range
Private [COLOR="Navy"]Sub[/COLOR] Worksheet_Change(ByVal Target [COLOR="Navy"]As[/COLOR] Range)
 [COLOR="Navy"]If[/COLOR] Rng [COLOR="Navy"]Is[/COLOR] Nothing [COLOR="Navy"]Then[/COLOR]
        [COLOR="Navy"]Set[/COLOR] Rng = Target
    [COLOR="Navy"]Else[/COLOR]
        Rng.Interior.Color = vbYellow
        [COLOR="Navy"]If[/COLOR] Not temp [COLOR="Navy"]Is[/COLOR] Nothing [COLOR="Navy"]Then[/COLOR] temp.Interior.Color = xlNone
        [COLOR="Navy"]Set[/COLOR] temp = Rng
        [COLOR="Navy"]Set[/COLOR] Rng = Target
    [COLOR="Navy"]End[/COLOR] If
[COLOR="Navy"]End[/COLOR] [COLOR="Navy"]Sub[/COLOR]
Regards Mick
 
Upvote 0

Excel Facts

What did Pito Salas invent?
Pito Salas, working for Lotus, popularized what would become to be pivot tables. It was released as Lotus Improv in 1989.
You're welcome.
You might be interested the code below:-
It is the same as the previous code, except if you change a cell that has a particular colour, then that cell will retain its original colour when it comes to being changed back as you proceed with the code.

Code:
Option Explicit
[COLOR=navy]Dim[/COLOR] Rng [COLOR=navy]As[/COLOR] Range, temp [COLOR=navy]As[/COLOR] Range, c [COLOR=navy]As[/COLOR] [COLOR=navy]Long,[/COLOR] Ray()
Private [COLOR=navy]Sub[/COLOR] Worksheet_Change(ByVal Target [COLOR=navy]As[/COLOR] Range)
[COLOR=navy]Dim[/COLOR] col [COLOR=navy]As[/COLOR] [COLOR=navy]Long[/COLOR]
    c = c + 1
    ReDim Preserve Ray(c)
    Ray(c) = Target.Interior.Color
    [COLOR=navy]If[/COLOR] c > 2 [COLOR=navy]Then[/COLOR] col = Ray(UBound(Ray) - 2)
    [COLOR=navy]If[/COLOR] Rng [COLOR=navy]Is[/COLOR] Nothing [COLOR=navy]Then[/COLOR]
        [COLOR=navy]Set[/COLOR] Rng = Target
    [COLOR=navy]Else[/COLOR]
        Rng.Interior.Color = vbYellow
        If Not temp Is Nothing Then temp.Interior.Color = col 
        [COLOR=navy]Set[/COLOR] temp = Rng
        [COLOR=navy]Set[/COLOR] Rng = Target
    [COLOR=navy]End[/COLOR] If
[COLOR=navy]End[/COLOR] [COLOR=navy]Sub[/COLOR]
Regards Mick
 
Last edited:
Upvote 0

Forum statistics

Threads
1,224,825
Messages
6,181,190
Members
453,020
Latest member
Mohamed Magdi Tawfiq Emam

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