ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   What cell caused the worksheet change event (https://www.excelbanter.com/excel-programming/376373-what-cell-caused-worksheet-change-event.html)

Keith

What cell caused the worksheet change event
 
I want to run a routine on my worksheet when the change event happens. This
event requires me to know the row and column of the cell that was changed,
but if the user pressed return to complete the entry them the cursor moved
down the the next row and if they press the Tab key it moves to the next
column.

Is there any way to find out which cell was changed?

Jim Thomlinson

What cell caused the worksheet change event
 
Worksheet_Change has one argument and that is Target which is the range that
was changed so this should work for you...

Private Sub Worksheet_Change(ByVal Target As Range)
MsgBox Target.Column & " - " & Target.Row
End Sub

You might be thinking of selection change where target returns the currently
selected range.
--
HTH...

Jim Thomlinson


"Keith" wrote:

I want to run a routine on my worksheet when the change event happens. This
event requires me to know the row and column of the cell that was changed,
but if the user pressed return to complete the entry them the cursor moved
down the the next row and if they press the Tab key it moves to the next
column.

Is there any way to find out which cell was changed?


bobbo

What cell caused the worksheet change event
 
you can set the last range to a static value

Private Sub Workbook_SheetSelectionChange(ByVal Sh As Object, ByVal
Target As Range)
Static OldRange As Range
dim i as integer
dim j as integer

if not OldRange is nothing then
i = OldRange.row
j = OldRange.column
end if

set OldRange = Target

End Sub




Keith wrote:
I want to run a routine on my worksheet when the change event happens. This
event requires me to know the row and column of the cell that was changed,
but if the user pressed return to complete the entry them the cursor moved
down the the next row and if they press the Tab key it moves to the next
column.

Is there any way to find out which cell was changed?



bobbo

What cell caused the worksheet change event
 
Ignore my post I thought you were asking about the SheetSelectionChange
event.

bobbo wrote:
you can set the last range to a static value

Private Sub Workbook_SheetSelectionChange(ByVal Sh As Object, ByVal
Target As Range)
Static OldRange As Range
dim i as integer
dim j as integer

if not OldRange is nothing then
i = OldRange.row
j = OldRange.column
end if

set OldRange = Target

End Sub




Keith wrote:
I want to run a routine on my worksheet when the change event happens. This
event requires me to know the row and column of the cell that was changed,
but if the user pressed return to complete the entry them the cursor moved
down the the next row and if they press the Tab key it moves to the next
column.

Is there any way to find out which cell was changed?



Keith

What cell caused the worksheet change event
 
That was exactly wat I was looking for.

Thanks Jim.

"Jim Thomlinson" wrote:

Worksheet_Change has one argument and that is Target which is the range that
was changed so this should work for you...

Private Sub Worksheet_Change(ByVal Target As Range)
MsgBox Target.Column & " - " & Target.Row
End Sub

You might be thinking of selection change where target returns the currently
selected range.
--
HTH...

Jim Thomlinson


"Keith" wrote:

I want to run a routine on my worksheet when the change event happens. This
event requires me to know the row and column of the cell that was changed,
but if the user pressed return to complete the entry them the cursor moved
down the the next row and if they press the Tab key it moves to the next
column.

Is there any way to find out which cell was changed?



All times are GMT +1. The time now is 04:30 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com