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
 

Excel Facts

Formula for Yesterday
Name Manager, New Name. Yesterday =TODAY()-1. OK. Then, use =YESTERDAY in any cell. Tomorrow could be =TODAY()+1.
Try this:-
To load code :- Right click sheet Tab, select "View Code", Vb window appears.
Paste (at top of code page) code into Vbwindow, close Vbwindow.
To run code select cell between columns "A & N" ( alter in code as required), cell will turn "yellow", select another cell, original cell returns to previous colour new cell turns "Yellow".
Code:
Option Explicit
[COLOR="Navy"]Dim[/COLOR] Rng [COLOR="Navy"]As[/COLOR] Range, ray
Private [COLOR="Navy"]Sub[/COLOR] Worksheet_SelectionChange(ByVal Target [COLOR="Navy"]As[/COLOR] Range)
[COLOR="Navy"]Dim[/COLOR] Dn [COLOR="Navy"]As[/COLOR] Range, c [COLOR="Navy"]As[/COLOR] [COLOR="Navy"]Long,[/COLOR] col [COLOR="Navy"]As[/COLOR] [COLOR="Navy"]Long[/COLOR]
[COLOR="Navy"]If[/COLOR] Not Intersect(Target, Range("A:N")) [COLOR="Navy"]Is[/COLOR] Nothing [COLOR="Navy"]Then[/COLOR]
[COLOR="Navy"]If[/COLOR] Not Rng [COLOR="Navy"]Is[/COLOR] Nothing [COLOR="Navy"]Then[/COLOR]
    c = 0
    [COLOR="Navy"]For[/COLOR] [COLOR="Navy"]Each[/COLOR] Dn [COLOR="Navy"]In[/COLOR] Rng
       c = c + 1
       Dn.Interior.ColorIndex = ray(c, 1)
       Dn.Borders.LineStyle = xlNone
    [COLOR="Navy"]Next[/COLOR] Dn
[COLOR="Navy"]End[/COLOR] If
c = 0
[COLOR="Navy"]Set[/COLOR] Rng = Target
ReDim ray(1 To Rng.Count, 1 To 2)
    [COLOR="Navy"]For[/COLOR] [COLOR="Navy"]Each[/COLOR] Dn [COLOR="Navy"]In[/COLOR] Rng
        c = c + 1
        ray(c, 1) = Dn.Interior.ColorIndex
    [COLOR="Navy"]Next[/COLOR] Dn
    Target.Interior.ColorIndex = 6
    Target.Borders.Weight = 2
[COLOR="Navy"]End[/COLOR] If
[COLOR="Navy"]End[/COLOR] [COLOR="Navy"]Sub[/COLOR]
Regards Mick
 
Upvote 0
Deer Mick your code is highlighting active cell.
i need to highlight that cell which i used last time and it should be dynamic. e.g
if i enter some data into A1 and then move to another cell B1 then A1 will highlight for me and when i enter data into B1 and move to F3 or any other cell then my highlight remove from A1 and B1 will highlight for me which i used last time
 
Upvote 0
Try this:-
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_SelectionChange(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
 
Last edited:
Upvote 0
Deer mick thank you so much for your responding.
you are very close to my question your code is really working but here a problem " your code is highlighting every last cell but i need to highlight that last cell which i modified "
 
Upvote 0

Forum statistics

Threads
1,216,031
Messages
6,128,424
Members
449,450
Latest member
gunars

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