Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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 |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
How do you insert & delete rows in a protected worksheet? | Excel Worksheet Functions | |||
How to code to insert / delete any worksheet? | Excel Worksheet Functions | |||
How to program excel to insert / delete any worksheet? | Excel Worksheet Functions | |||
Unable to delete or insert a worksheet. | Excel Discussion (Misc queries) | |||
Protect Worksheet but allow to insert or delete rows | Excel Discussion (Misc queries) |