How to target Worksheet_change() on only a specific named column of a table in the sheet

chx77

New Member
Joined
Sep 15, 2021
Messages
5
Office Version
  1. 365
Platform
  1. Windows
Hi
Hope to have some advice on this problem. In worksheet "Work" I have a table named "tbl_work" which contains named columns "colA", "colB", "colC".... I want something to happen only when changes occur in "colB".

Private Sub Worksheet_Change(ByVal Target As Range)

Application.EnableEvents = True
On Error GoTo Exitsub

Set tbl = Worksheets("Work").ListObjects("tbl_work")
If Target.Address = tbl.ListColumns("colB").Address Then
"something to happen"
End if
Application.EnableEvents = True
Exitsub:
Application.EnableEvents = True
End Sub

It has however no effect.
Thanks
chx77
 

Excel Facts

Quick Sum
Select a range of cells. The total appears in bottom right of Excel screen. Right-click total to add Max, Min, Count, Average.
VBA Code:
Set cc = intersect(target, tbl.ListColumns("colB").range)
If not cc is nothing Then
... Something happens ...
 
Upvote 0
Another option
VBA Code:
Set tbl = Worksheets("Work").ListObjects("tbl_work")
If Not Intersect(Target, tbl.ListColumns("colB")) Is Nothing Then
"something to happen"
End If
 
Upvote 0
Another one

VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
  If Not Intersect(Target, Range("tbl_work[colB]")) Is Nothing Then
    'something
  End If
End Sub
 
Upvote 0
Solution
Hi bobsan42, Fluff, and Peter_SSs
Thank you for your reply. I tried and found only Peter'_SSs code works in my case though bobsan42 and FLuff's codes totally make sense to me.
Thank you all.

 
Upvote 0
Glad we could help & thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,223,888
Messages
6,175,206
Members
452,618
Latest member
Tam84

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