ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Delete sheet (https://www.excelbanter.com/excel-programming/388286-delete-sheet.html)

tom

Delete sheet
 
I am wanting to enter the name of a worksheet in D1, and have a macro that
looks for the worksheet with that name and automatically delete it without
prompts or warnings. Can someone help me out with that code?

Thanks so much

Don Guillett

Delete sheet
 
right click sheet tabview codeinsert this. If you make a mistake, don't
SAVE the workbook.

Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Address < "$D$1" Then Exit Sub
Application.DisplayAlerts = False
Sheets(Target.Value).Delete
Application.DisplayAlerts = True
End Sub
--
Don Guillett
SalesAid Software

"Tom" wrote in message
...
I am wanting to enter the name of a worksheet in D1, and have a macro that
looks for the worksheet with that name and automatically delete it without
prompts or warnings. Can someone help me out with that code?

Thanks so much



Mike

Delete sheet
 
Same as Dons but with code for errors
Private Sub Worksheet_Change(ByVal Target As Range)
Dim strmsg As String
On Error GoTo SheetError
If Target.Address < "$D$1" Then Exit Sub
Application.DisplayAlerts = False
Sheets(Target.Value).Delete
Application.DisplayAlerts = True
SheetError:
strmsg = "Error # " & Err & " : " & Error(Err)
Select Case Err

Case 9:

MsgBox strmsg & vbCrLf & "Sheet you selected is not a valid sheet"
Exit Sub

Case Else:

MsgBox strmsg
Exit Sub
End Select
End Sub

"Tom" wrote:

I am wanting to enter the name of a worksheet in D1, and have a macro that
looks for the worksheet with that name and automatically delete it without
prompts or warnings. Can someone help me out with that code?

Thanks so much


tom

Delete sheet
 
Thanks Don!

"Don Guillett" wrote:

right click sheet tabview codeinsert this. If you make a mistake, don't
SAVE the workbook.

Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Address < "$D$1" Then Exit Sub
Application.DisplayAlerts = False
Sheets(Target.Value).Delete
Application.DisplayAlerts = True
End Sub
--
Don Guillett
SalesAid Software

"Tom" wrote in message
...
I am wanting to enter the name of a worksheet in D1, and have a macro that
looks for the worksheet with that name and automatically delete it without
prompts or warnings. Can someone help me out with that code?

Thanks so much





All times are GMT +1. The time now is 04:49 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com