Putting woirksheet name into a variable

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

Guest

I have a form where a new sheet is created in a workbook. Everytime a sheet
is created it incraments up (sheet1, sheet2, sheet3, sheet4). I was tring to
put the active sheet name into a varable but I do not know the syntax.
 
try this:-

Sub filefile()
With ThisWorkbook
.Sheets.Add After:=.Sheets(.Sheets.Count)
End With
myName = ActiveSheet.Name
msgbox myName
End Sub
 
I have a form where a new sheet is created in a workbook. Everytime a sheet
is created it incraments up (sheet1, sheet2, sheet3, sheet4). I was tring to
put the active sheet name into a varable but I do not know the syntax.

Dim sWshName as string
sWshName=activeworkbook.worksheets(activeworkbook.worksheets.count).name

should do the job
 
Option Explicit

Sub zeyger()

Dim ws As Worksheet
Dim sName As String

sName = "Zeyger"

Worksheets.Add
ActiveSheet.Name = sName

End Sub


hth!
susan
 

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