Macro To Delete/Add & Rename/Arrange Sheets
The macro below will delete the sheets as required. It requires a sheet
called Template (templet?) and copies the sheet and renames the new sheet.
It also expects the Range of number to be on a sheet called Numbers. change
the range on this sheet as required. the code uses advancefilter to get the
unique numbers in this range.
Sub Addtemplet()
'remove sheets
Application.DisplayAlerts = False
DeleteSheet = False
For Each sht In Sheets
If DeleteSheet = False Then
If sht.Name = "" Then
DeleteSheet = True
End If
Else
If sht.Name = "<" Then
Exit For
End If
sht.Delete
End If
Next sht
Application.DisplayAlerts = False
With Sheets("Numbers")
Set UniqueNumbers = Range("A1:A25").AdvancedFilter _
(Action:=xlFilterInPlace, _
unique:=True)
For Each Num In UniqueNumbers
Set newsht = Worksheet("Template").Copy(befo=Sheets("<"))
newsht.Name = Num
Next Num
End Sub
"steven.holloway" wrote:
I have lost my way on trying to create this macro, can anyone help please.
Many thanks for any help
1) I have variable number of sheets between two sheets called "" & "<", I
would like the first part of the macro to delete all sheets (if any) between
these two sheets.
2) I have a range of numbers (that can be repeated), I would like the macro
to run through the range and add a "TEMPLATE" sheet in between the two sheets
"" & "<" and rename the new sheet equal to the current number in the range,
but only if it does not already exist.
3) I would like the sheets in between the two sheets "" & "<" to be shown
in accending order
PS. I already have about 60 sheets in the workbook and the above macro could
up to another 40+, is there a limit to the number of sheets a macro can add?
|