Whats wrong with this line of code?

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Worksheets.Add.name = range_s after:=Worksheets(Worksheets.Count)

Comes up with the error 'Compile error - Expected end of statement'

Thanks
 
Edgar,

Don't think you can name it and place it in one statement. Try

Set oWs = Worksheets.Add(after:=Worksheets(Worksheets.Count))
oWs.Name = range_s
 
Putting the "name" at the end should do it.

Worksheets.Add(After:=Worksheets(Worksheets.Count)).Name = "Test"
 
You can also do it this way:

Sub AddSheet()
range_s = "NewSheet"
Worksheets.Add(after:=Worksheets(Worksheets.Count)).Name = range_s
End Sub
 
I live and learn <vbg>

Bob

Tom Ogilvy said:
You can also do it this way:

Sub AddSheet()
range_s = "NewSheet"
Worksheets.Add(after:=Worksheets(Worksheets.Count)).Name = range_s
End Sub
 

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

Back
Top