ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   help with code please (https://www.excelbanter.com/excel-programming/376109-help-code-please.html)

Greg[_33_]

help with code please
 
Hi I have a macro which inserts a new worksheet at the end of the workbook
but the problem is when I click on cancel in the Inputbox it needs
debugging.

How can I change the code below to remove that particular worksheet when the
cancel button is pressed on the inputbox.

Worksheets.Add.Move after:=Worksheets(Worksheets.Count)
Dim NAMED As String
NAMED = InputBox("WHAT IS THE NAME OF THE WORKSHEET?")
ActiveSheet.Name = NAMED


Thanks

greg



Stefi

help with code please
 
Worksheets.Add.Move after:=Worksheets(Worksheets.Count)
Dim NAMED As String
NAMED = InputBox("WHAT IS THE NAME OF THE WORKSHEET?")
If NAMED < "" Then
ActiveSheet.Name = NAMED
Else
' statements in case of Cancel
End If

Regards,
Stefi

€˛Greg€¯ ezt Ć*rta:

Hi I have a macro which inserts a new worksheet at the end of the workbook
but the problem is when I click on cancel in the Inputbox it needs
debugging.

How can I change the code below to remove that particular worksheet when the
cancel button is pressed on the inputbox.

Worksheets.Add.Move after:=Worksheets(Worksheets.Count)
Dim NAMED As String
NAMED = InputBox("WHAT IS THE NAME OF THE WORKSHEET?")
ActiveSheet.Name = NAMED


Thanks

greg




Ole Michelsen

help with code please
 
Hi Greg

When you press cancel the input returns a empty string. You can't name a
sheet with a empty string. So you has to respond in a reasonable way to the
respond like: If name = "" then do something.

Ole

"Greg" wrote in message
...
Hi I have a macro which inserts a new worksheet at the end of the workbook
but the problem is when I click on cancel in the Inputbox it needs
debugging.

How can I change the code below to remove that particular worksheet when
the cancel button is pressed on the inputbox.

Worksheets.Add.Move after:=Worksheets(Worksheets.Count)
Dim NAMED As String
NAMED = InputBox("WHAT IS THE NAME OF THE WORKSHEET?")
ActiveSheet.Name = NAMED


Thanks

greg




Don Guillett

help with code please
 
Sub WrongSheetName()
Sheets.Add After:=Sheets(Sheets.Count)
On Error GoTo wrongname
ActiveSheet.Name = InputBox("Sheet Name?")
Exit Sub
wrongname:
Application.DisplayAlerts = False
ActiveSheet.Delete
Application.DisplayAlerts = True
MsgBox "Name used Try again"
End Sub

--
Don Guillett
SalesAid Software

"Greg" wrote in message
...
Hi I have a macro which inserts a new worksheet at the end of the workbook
but the problem is when I click on cancel in the Inputbox it needs
debugging.

How can I change the code below to remove that particular worksheet when
the cancel button is pressed on the inputbox.

Worksheets.Add.Move after:=Worksheets(Worksheets.Count)
Dim NAMED As String
NAMED = InputBox("WHAT IS THE NAME OF THE WORKSHEET?")
ActiveSheet.Name = NAMED


Thanks

greg





All times are GMT +1. The time now is 11:34 PM.

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