Help with Selection Count vba

decadence

Well-known Member
Joined
Oct 9, 2015
Messages
525
Office Version
  1. 365
  2. 2016
  3. 2013
  4. 2010
  5. 2007
Platform
  1. Windows
Hi, I am trying to set if statements so that only more than 1 column can be selected before the code runs, However I am having trouble with if the cells selected are more than 1 as it thinks the columns have been selected. Is there a way round this?

Code:
    If Selection.Cells.Count = 1 Then Exit Sub
    If Selection.Cells.Count > 1 Then Exit Sub '<--------
    If Selection.Columns.Count = 1 Then Exit Sub
 

Excel Facts

Wildcard in VLOOKUP
Use =VLOOKUP("Apple*" to find apple, Apple, or applesauce
I don't understand the second line. Between the first and second lines you have covered every possibility (other than no cells being selected) so the odds of your code ever running are pretty small.
 
Upvote 0
Hi RoryA, What I am trying to achieve is the end user can only select 2 or more columns for the code to continue, if they select Individual or multiple cells then exit the sub.
 
Upvote 0
Not sure if this is what you're after
Code:
    With Selection
      If .Columns.Count = 1 Then Exit Sub
      If Not .Cells.CountLarge / .Columns.Count = 1048576 Then Exit Sub
   End With
This will exit the sub if the user has not selected 2 or more complete columns. Assumes using xl 2007 or later
 
Upvote 0
Hi Fluff, Yes this is Exactly what I am after, Thank you
 
Upvote 0
Glad to help & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,214,584
Messages
6,120,385
Members
448,956
Latest member
JPav

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