How to capture the address of an original cell that is being changed as target in Sheet_Change event?

mkvarious

New Member
Joined
Jan 24, 2013
Messages
44
Hello,

I have a problem that I though I overcame but seems it is not the case.
The original problem originated there:
http://www.mrexcel.com/forum/excel-questions/681429-how-get-worksheet_selection-change-work.html

Thanks to the above thread I adjusted my macro:
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
Dim rng As Range
Dim który As Long
Set rng = Columns(8)
If Intersect(Target, rng) Is Nothing Then Exit Sub
    który = ActiveCell.Row
    Cells(który, 8).Offset(0, 1).Formula = "=weeknum(" & Cells(który, 8).Address & ",2)"
End Sub

I thought it was working but then I realized that Change event works pretty different based on what button user presses and not which cell it has originated from. see a link w JPG below to see what my point is:
https://docs.google.com/presentation/d/1z_77av56RlXYD7lCw9u3mddamSCwMrMzejuGNdmuOR0/edit

if we start from cell H18, then based on which button we press then Excel says what is changed cell address.
  1. when ctrl + enter is pressed then it shows the same address as the cell we originated from: H18
  2. when delete is pressed then it shows the same address as the cell we originated from: H18
  3. when tab is pressed then it shows different address to that we originated from: I18
  4. when right arrow is pressed then it shows different address to that we originated from: I18
  5. when left arrow is pressed then it shows different address to that we originated from: G18
  6. when up arrow is pressed then it shows different address to that we originated from: H17
  7. when down arrow is pressed then it shows different address to that we originated from: H19
  8. when enter is pressed then it shows different address to that we originated from: H19

So out of 8 event only 2 are related directly to the same original cell. then additional 3 events are related to the same row which is in the end not that bad for me as I may use row counter to populate formula in I column.
But my real problem is how to deal with 3 remaining events that show cell address in a different row comparing to what I originated from?
If users enters date, then presses: up arrow, down arrow or what's more likely enter then my formula will be written in incorrect row!

Can you kindly advice:
  1. For my file I need to address the problem with the last 3 events: up arrow, down arrow and enter. How can I keep the original row of the cell I was changing, so in the described example row 18???
  2. For my future knowledge, if I ever need to capture the exact address of the cell I originated from REGARDLESS of what button is being pressed, how do I do that?

Please share some knowledge.
Thank you in advance.

mkvarious
 

Excel Facts

Save Often
If you start asking yourself if now is a good time to save your Excel workbook, the answer is Yes
mkvarious,

No matter how you enter the data, Target will still reference the cell just changed.

With your code który = ActiveCell.Row you are are getting the row of the cell you have just moved to.

Try changing to który = Target.Row

Hope that helps.
 
Upvote 0

Forum statistics

Threads
1,215,372
Messages
6,124,531
Members
449,169
Latest member
mm424

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