VBA to test if ActiveCell is in a specific column of a ListObject table before performing an action

team_qq

New Member
Joined
Jan 20, 2011
Messages
3
I'm trying to create a test before allowing a DoubleClick function to ensure that the DoubleClick only occurs in a particular column (the first column) of a table ("Table9"), before copying the contents of the ActiveCell that was clicked to a cell (C4) on a different worksheet.

The code below errors out with my test, that is attempting to establish a logic function to test if the Active Cell is in Column 1 of the ListObject Table 9.

Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
If Intersect(ActiveCell, ActiveSheet.ListObjects("Table9").ListColumns(1).DataBodyRange) Then
ActiveCell.Copy Worksheets("Doctor Detail").Range("C4")
Worksheets("Doctor Detail").Activate
End If

End Sub


I'd appreciate any suggestions how to make this function properly.

Thanks
 

Excel Facts

Can you sort left to right?
To sort left-to-right, use the Sort dialog box. Click Options. Choose "Sort left to right"
Try this
VBA Code:
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, cancel As Boolean)
    On Error GoTo Escape
    Application.EnableEvents = False
    If Not Intersect(Me.ListObjects("Table9").ListColumns(1).DataBodyRange, Target) Is Nothing Then
        cancel = True
        Target.Copy Worksheets("Doctor Detail").Range("C4")
    End If
Continue:
    Application.EnableEvents = True
    Exit Sub
Escape:
    MsgBox "Error " & Err.Number & ": " & Err.Description
    Resume Continue
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,624
Messages
6,120,591
Members
448,973
Latest member
ksonnia

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