How the get the column or row number of a changed cell on Worksheet_Change condition?

minmark

New Member
Joined
Jul 18, 2016
Messages
44
Dear Gents,

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
If Not Application.Intersect(Target, Range("B2:B5")) Is Nothing Then
       Cancel = True    
ActCol = Activecell.Column
 'other macro
According to above codes, If the user change the value of B2 to B5 and press "tab" on keyboard
, the activecell.column will be 2. But if the user click other cells instead of press tab, the activecell.column
will not be 2.

Please help me to figure out how to get the changed cell's row or column if user didn't press "tab" key in this condition.

Thanks.
 
Last edited:

Excel Facts

Why are there 1,048,576 rows in Excel?
The Excel team increased the size of the grid in 2007. There are 2^20 rows and 2^14 columns for a total of 17 billion cells.
try this

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
    Dim c As Long, r As Long
    If Not Application.Intersect(Target, Range("B2:B5")) Is Nothing Then
        c = Target.Column:  r = Target.Row
        MsgBox "column " & c & vbCr & "row " & r, , "Amended Cell..."
    End If
End Sub
 
Upvote 0
Please help me to figure out how to get the changed cell's row or column if user didn't press "tab" key in this condition.
Given that you are using
Rich (BB code):
If Not Application.Intersect(Target, Range("B2:B5")) Is Nothing Then
then the column of the changed cell(s) in the range B2:B5 would always be 2.

If you were looking for the row of the changed cell (& assuming only 1 cell was changed), then use something like
Rich (BB code):
ActRow = Target.Row
 
Upvote 0

Forum statistics

Threads
1,214,407
Messages
6,119,332
Members
448,888
Latest member
Arle8907

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