Adding new sheet problem-Macro

P

pikapika13

I'm very new to this. I'm trying to open a new worksheet and call it a
name.
However, I never know what sheet name excel is going to give me:
sometimes "Sheet1" or "Sheet10". It depends on how many times I run
the macro.
Is there a way to convert this:
' Workbooks.Add
Sheets("Sheet1").Name = "M1"

to something more friendly?
 
J

JE McGimpsey

one way:

With Worksheets.Add
On Error Resume Next 'in case M1 exists
.Name = "M1"
On Error GoTo 0
End With
 
G

Guest

When the sheet's first made, it's the active sheet so I'd change the second
line to:
ActiveSheet.Name = "M1"
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top