Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,670
Default How to program to insert / delete any worksheet?

Does anyone have any suggestions on how to program excel to insert / delete
any worksheet?
For example,
Under column A, there is a list of numbers, such as
1,4,9, ...
If there is no existing worksheet named "1", then insert a new worksheet
named under "1", else do nothing.
Repeat this process until the end of the list.

For checking, if 3 is not included under column A and there is an existing
worksheet named under "3", then delete it.
Repeat this process until the last worksheet checked.

Does anyone have any suggestions on how to code it in excel?
Thanks in advance for any suggestions
Eric

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9,101
Default How to program to insert / delete any worksheet?

Make sure the in both functions you change With Sheets("Sheet1") to be the
sheet with the sheet names.

Sub AddSheets()

RowCount = 1
With Sheets("Sheet1")
Do While .Range("A" & RowCount) < ""
found = False
For Each sht In ThisWorkbook.Sheets
If .Range("A" & RowCount) = sht.Name Then
found = True
Exit For
End If
Next sht
If found = False Then
Worksheets.Add _
after:=ThisWorkbook.Sheets(Sheets.Count)
ActiveSheet.Name = .Range("A" & RowCount)
End If
RowCount = RowCount + 1
Loop
End With
End Sub
Sub RemoveSheets()

Application.DisplayAlerts = False
For Each sht In ThisWorkbook.Sheets
With Sheets("Sheet1")
If sht.Name < .Name Then
Set c = .Columns("A:A").Find(what:=sht.Name, _
LookIn:=xlValues, lookat:=xlWhole)
If c Is Nothing Then
Sheets(sht.Name).Delete
End If
End If
End With
Next sht
Application.DisplayAlerts = False
End Sub


"Eric" wrote:

Does anyone have any suggestions on how to program excel to insert / delete
any worksheet?
For example,
Under column A, there is a list of numbers, such as
1,4,9, ...
If there is no existing worksheet named "1", then insert a new worksheet
named under "1", else do nothing.
Repeat this process until the end of the list.

For checking, if 3 is not included under column A and there is an existing
worksheet named under "3", then delete it.
Repeat this process until the last worksheet checked.

Does anyone have any suggestions on how to code it in excel?
Thanks in advance for any suggestions
Eric

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
How do you insert & delete rows in a protected worksheet? Tiffany G. Excel Worksheet Functions 1 February 3rd 09 01:26 AM
How to code to insert / delete any worksheet? Eric Excel Worksheet Functions 1 March 2nd 08 10:02 PM
How to program excel to insert / delete any worksheet? Eric Excel Worksheet Functions 1 March 2nd 08 09:49 PM
Unable to delete or insert a worksheet. dmarten Excel Discussion (Misc queries) 2 October 31st 06 05:03 PM
Protect Worksheet but allow to insert or delete rows Bob L Hilliard Excel Discussion (Misc queries) 2 June 9th 05 02:08 PM


All times are GMT +1. The time now is 03:21 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"