Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 465
Default Check for two sheets. Add or subtract as necessary.


HI

I'm hoping someone can help with a short routine.

I need to check that there are 2 worksheets present in the workbook.

If there is only one , then a second has to be added to the end.

So tabs :

Sheet1

Becomes

Sheet1 Sheet2


If there are more than 2 then the additional ones should be deleted form
the end.

So tabs:

Sheet1 Sheet2 Sheet3 ...

Becomes

Sheet1 Sheet2



Grateful for your help.



Best Wishes
  #2   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 3,872
Default Check for two sheets. Add or subtract as necessary.

Hi Colin,

Am Wed, 18 Jun 2014 14:57:38 +0100 schrieb Colin Hayes:

Sheet1

Becomes

Sheet1 Sheet2


Sheet1 Sheet2 Sheet3 ...

Becomes

Sheet1 Sheet2


try:

Sub SheetCheck()
Dim i As Long

Select Case Sheets.Count
Case 1
Sheets.Add after:=Sheets(Sheets.Count)
Case Is 2
For i = Sheets.Count To 3 Step -1
Application.DisplayAlerts = False
Sheets(i).Delete
Application.DisplayAlerts = True
Next
End Select
End Sub


Regards
Claus B.
--
Vista Ultimate / Windows7
Office 2007 Ultimate / 2010 Professional
  #3   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 465
Default Check for two sheets. Add or subtract as necessary.


Sub SheetCheck()
Dim i As Long

Select Case Sheets.Count
Case 1
Sheets.Add after:=Sheets(Sheets.Count)
Case Is 2
For i = Sheets.Count To 3 Step -1
Application.DisplayAlerts = False
Sheets(i).Delete
Application.DisplayAlerts = True
Next
End Select
End Sub


Regards
Claus B.


Hi Claus

OK thanks for this. Perfect first time.


Best Wishes ,

Colin
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Check date range on three sheets? Geo Excel Discussion (Misc queries) 1 September 28th 09 11:26 AM
Basic example formula needed to link between sheets add/subtract gnagy84 New Users to Excel 1 January 2nd 08 05:44 PM
How do I check several sheets for data in a particular cell? lee Excel Discussion (Misc queries) 0 October 25th 06 07:47 AM
Check - Similar Row contents - Different Sheets al007 Excel Programming 4 November 10th 05 10:15 PM
How to subtract many cell areas (between sheets) Imbecill[_2_] Excel Programming 4 June 2nd 04 02:28 PM


All times are GMT +1. The time now is 03:40 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"