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
Andreas HermleTeam leaderAsked:
Who is Participating?
Saqib Husain, SyedConnect With a Mentor EngineerCommented:
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
Saqib Husain, SyedEngineerCommented:
[ fanpages ]Connect With a Mentor 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] :)


Andreas HermleTeam leaderAuthor Commented:
Dear both,

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

Regards, Andreas
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.