Do things based on previously active cell

Peteor

Board Regular
Joined
Mar 16, 2018
Messages
152
I have the following code:

Private Sub Worksheet_Change(ByVal Target As Range)
If Range("W2") <= Range("W1") Then
If Not Intersect(Target, Range("A:U")) Is Nothing Then
Call Automatic_Highlights
Else
End If
End If
End Sub

Which Calls the following:

Sub Automatic_Highlights()
Dim TargetCell As Range
Dim CellReturn As Range


TargetRow = ActiveCell.Row
TargetCol = ActiveCell.Column


ActiveCell.Interior.ColorIndex = 37


Cells(TargetRow, 21).Select


ActiveCell.Interior.ColorIndex = 37


Cells(TargetRow, TargetCol).Select


End Sub

This code functions perfectly except for 1 thing. Imagine you are editing cell A2. When you finish editing cell A2, you click to another cell on the sheet (or even press enter). Sub Automatic_Highlight will then be called for the currently active cell (which will not be cell A2). How do I re-write this for Sub Automatic_Highlight to highlight cell A2 (or whatever cell is being edited, "A2" is just an example)?
 

Excel Facts

Why does 9 mean SUM in SUBTOTAL?
It is because Sum is the 9th alphabetically in Average, Count, CountA, Max, Min, Product, StDev.S, StDev.P, Sum, VAR.S, VAR.P.

Forum statistics

Threads
1,216,604
Messages
6,131,697
Members
449,666
Latest member
Tommy2Tables365

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