Solved

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

Posted on 2013-05-27
4
270 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

U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

Question has a verified solution.

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

Convert between Excel file formats (.XLS, .XLSX, .XLSM) with/without macro option David Miller (dlmille) Intro Over this past Fall, I've had the opportunity to see several similar requests and have developed a couple related solutions associate…
This tutorial explains how to create a series of drop-down lists that are dependent upon prior selections to guide (“force”) the user to make the correct selection and reduce data errors within Microsoft Excel. Excel 2010 was used for this tutorial;…
This Micro Tutorial demonstrate the bugs in Microsoft Excel for Mac with Pivot Charts.
This Micro Tutorial will demonstrate how to use a scrolling table in Microsoft Excel using the INDEX function.

825 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