Solved

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

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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

What is a Form List Box? (skip if you know this) The forms List Box is the alternative to the ActiveX list box. If you are using excel 2007, you first make sure you have a developer tab (click the Orb)->"Excel Options"->Popular->"Show Developer tab…
This article will guide you to convert a grid from a picture into Excel format using Microsoft OneNote and no other 3rd party application.
The viewer will learn how to create a normally distributed random variable in Excel, use a normal distribution to simulate the return on an investment over a period of years, Create a Monte Carlo simulation using a normal random variable, and calcul…
This Micro Tutorial demonstrate the bugs in Microsoft Excel for Mac with Pivot Charts.

708 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

13 Experts available now in Live!

Get 1:1 Help Now