Solved

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

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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

This code takes an Excel list of URL’s and adds a header titled “URL List”. It then searches through all URL’s in column “A”, looking for duplicates. When a duplicate is found, it is moved to the top of the list. The duplicate URL’s are then highlig…
Do you use a spreadsheet like Microsoft's Excel?  Have you ever wanted to link out to a non excel file on your computer or network drive?  This is the way I found to do it!
The viewer will learn how to use a discrete random variable to simulate the return on an investment over a period of years, create a Monte Carlo simulation using the discrete random variable, and create a graph to represent the possible returns over…
This Micro Tutorial demonstrate the bugs in Microsoft Excel for Mac with Pivot Charts.

735 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