MrExcel Publishing
Your One Stop for Excel Tips & Solutions

How do you do a conditional test to see if more than one sheet is selected?


Posted by Jasy M. on January 06, 2000 11:03 AM

Hi there,
It's me Jasy again. Yet again thanks very much to you Ivan for all your help. I would be lost without you. I have just one more problem. This is described below.

I have set up a form and want to do an error check that checks that no more than one sheet is selected before it does various calculations. You wouldn't know how to do a conditional test which says "If more than one sheet is selected then quit the routine". Sorry to bother you again, but your help would be much appreciated.

Thanks again,

Jasy M.


Posted by Ivan Moala on January 06, 2000 3:01 PM

Jasy
use; Thisworkbook.sheets.count
which gives you the number of sheets in the
active project.
ThisWorkbook always returns the workbook in which the code is running so it is better to use this.

Ivan

Posted by Chris on January 07, 2000 7:27 AM


This will display a message if more than one sheet is selected at run time. It does so by checking the caption of Excel (which adds "Group" if more than one sheet is selected).

Sub asdf()
If Right(Application.Caption, 7) = "[Group]" Then
MsgBox ("More than one sheet selected")
Else
'Do something
End If
End Sub

HTH,
Chris