• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 324
  • Last Modified:

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

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
AndreasHermle
Asked:
AndreasHermle
  • 2
2 Solutions
 
Saqib Husain, SyedEngineerCommented:
selection.count
0
 
[ fanpages ]IT Services ConsultantCommented:
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
 
Saqib Husain, SyedEngineerCommented:
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
 
AndreasHermleAuthor Commented:
Dear both,

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

Regards, Andreas
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

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.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now