Worksheet_SelectionChange if entire column is selected

Jim McCarthy

New Member
Joined
Aug 16, 2004
Messages
35
I have a sheet in which Cols A, B, C & D each has a macro that toggles autofilter ON/OFF based on the criterion selected for each column.

In the same sheet, columns M and N each contain a series of data and calculations. I sometimes need to manually copy the entire ccontents of one or both columns into adjacent columns (say copy col N to cols O, P & Q). However, if I forget to turn autofilter for col A, B C or D off before I copy and paste, I end up pasting only the filtered cells rather than the entire column contents, as intended.

What I need is an event handling subroutine that aurtomatically turns off autofilter when I select col M and/or N. I have played around with worksheet_SelectionChange but, being a VBA novice, have had no luck.

I would appreciate your help.

Thanks.
 

Excel Facts

How to find 2nd largest value in a column?
MAX finds the largest value. =LARGE(A:A,2) will find the second largest. =SMALL(A:A,3) will find the third smallest
Try

Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)

'if selected cell is within column M or N
If Not Intersect(Target, Columns("M:N")) Is Nothing Then
    'run code
End If

End Sub

Edit: Nevermind--I missed the "entire column" part of that, somehow :oops: My code will run when you select a single cell in either column, which isn't what you're asking.
 
Upvote 0
Hi,

Try this selection change event:
Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Target.Rows.Count = Rows.Count _
And (Target.Column = 13 Or Target.Column = 14) Then ActiveSheet.AutoFilterMode = False
End Sub
 
Upvote 0

Forum statistics

Threads
1,203,242
Messages
6,054,343
Members
444,717
Latest member
melindanegron

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