Solved

Check whether more than one cell is selected (contiguous or non-contiguous selections) using VBA

Posted on 2013-05-27
4
261 Views
Last Modified: 2013-05-30
Dear Experts:

I would like to have the following code snippet to start off my macro.

The macro is to check whether the user has currently more than one cell selected.

Helyp is much appreciated. Thank you very much in advance.

Regards, Andreas
0
Comment
Question by:AndreasHermle
  • 2
4 Comments
 
LVL 43

Expert Comment

by:Saqib Husain, Syed
ID: 39199345
selection.count
0
 
LVL 35

Assisted Solution

by:[ fanpages ]
[ fanpages ] earned 150 total points
ID: 39199357
Hi Andreas.

Try something similar to this:

  If Excel.Selection.Cells.Count > 1 Then
     MsgBox "More than one cell is selected", vbInformation Or vbOKOnly
  End If

Open in new window


[EDIT](You may also use Selection.Count as ssaqibh suggested)[/EDIT] :)

BFN,

fp.
0
 
LVL 43

Accepted Solution

by:
Saqib Husain, Syed earned 350 total points
ID: 39199413
On second thoughts you might need the cells part and something like

sc = 0
On Error Resume Next
sc = Selection.cells.Count
On Error GoTo 0
MsgBox sc & " cells selected"


to cover the possibility of shapes or controls being selected
0
 

Author Closing Comment

by:AndreasHermle
ID: 39207532
Dear both,

great job. Works as desired. Thank you very much for your professional help.

Regards, Andreas
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Sparklines have been introduced with Excel 2010 and are a useful tool for creating small in-cell charts, used for example in dashboards. Excel 2010 offers three different types of Sparklines: Line, Column and Win/Loss. What it does not offer is a…
Introduction While answering a recent question (http:/Q_27311462.html), I created an alternative function to the Excel Concatenate() function that you might find useful.  I tested several solutions and share the results in this article as well as t…
The viewer will learn how to simulate a series of sales calls dependent on a single skill level and learn how to simulate a series of sales calls dependent on two skill levels. Simulating Independent Sales Calls: Enter .75 into cell C2 – “skill leve…
This Micro Tutorial will demonstrate on a Mac how to change the sort order for chart legend values and decrpyt the intimidating chart menu.

896 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now