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

What is the shortcut key for Format Selection?
Ctrl+1 (the number one) will open the Format dialog for whatever is selected.
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,224,823
Messages
6,181,175
Members
453,021
Latest member
Justyna P

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