Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Simple-> new sheet 2

Status
Not open for further replies.

kingz2000

Programmer
May 28, 2002
304
DE
Hi,

I'd like to add a sheet, whereby I delete the sheet before if it exists.

Simple, I would have thought:)

strSheetName="XYZ"
On Error Resume Next
Sheets(strSheetName).Delete
On Error GoTo 0

Sheets.Add after:=(strSheetName)

however I get the error message "Application-defined or Object-defined error"

Can anyone help?

Thanx
 



Hi,
Code:
dim ws as worksheet

for each ws in worksheets
  if ws.name = strSheetName then
     ws.delete
     esit for
  end if
next


Skip,

[glasses]Just traded in my old subtlety...
for a NUANCE![tongue]
 
Sheets.Add after:=(strSheetName)
You want to add a sheet after one that doesn't exist ...

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
If you read the Sheet's Index before deleting the sheet, you should be able to add the new sheet after the sheet(Index-1), rather than after the sheet name, which no longer exists.
;-)

Cheers,
MiS


[navy]"We had to turn off that service to comply with the CDA Bill."[/navy]
- The Bastard Operator From Hell
 

No, I want to add a sheet, and call it 'strSheetname'!

Isn't that what "after" is for??

@skipvought:Thanks for the cleaner version of deleting the sheet.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top