PDA

View Full Version : Insert sheet



mpearce
04-14-2009, 09:55 AM
is there a way to insert a sheet as sheet4 not matter what?

I have code that runs and a new sheet gets inserted. The first time through it is sheet4, this is fine. But if the user chooses to run the code again, the sheet now becomes sheet5. The code references sheet4, so obviously it will error out because sheet4 does not exist in the workbook.

Is there any way around this?

Thanks

Bob Phillips
04-14-2009, 10:47 AM
What happens if there is already Sheet4?

p45cal
04-14-2009, 10:55 AM
presumably the code has the likes of
Sheets.add in it, and you refer to it with the likes of
Sheets("Sheet4").range("A1")
Replace with
Set xxx = Sheets.Add and refer to it as
xxx.range("A1") etc.