Karen Schaefer
asked on
Create new worksheet within workbook
Looking for the proper syntax to add a new worksheet when you need determining the next available Sheet name ("Sheet(?))
Sheets("Sheet(????????)"). Select
Sheets("Sheet(????????)").
Try this....
Sheets.Add(after:=Sheets(Sheets.Count)).Name = "Sheet" & Sheets.Count + 1
Hi,
pls try
pls try
Sub macro()
intMax = 0
For Each sh In ActiveWorkbook.Sheets
If sh.Name Like "Sheet#*" Then
intMax = WorksheetFunction.Max(intMax, Right(sh.Name, Len(sh.Name) - 5))
End If
Next
Sheets.Add(after:=Sheets(Sheets.Count)).Name = "Sheet" & intMax + 1
End Sub
Regards
ASKER
How do I use the wsname to rename the worksheet to "by State"
Dim WSname As Worksheet
Sheets("BillingFinal").Select
Worksheets.Add
WSname = ActiveSheet.name
WSname.Select
WSname.name = "By State"
ActiveWorkbook.PivotCaches.Create(SourceType:=xlExternal, SourceData:= _
ActiveWorkbook.Connections("ThisWorkbookDataModel"), Version:=6). _
CreatePivotTable TableDestination:="By State!R1C1", TableName:= _
"PivotTable1", DefaultVersion:=6
Cells(1, 1).Select
Sheets("By State").Select
Dim WSname As Worksheet
Sheets("BillingFinal").Sel ect
Worksheets.Add
set WSname = ActiveSheet.name
WSname.Select
WSname.name = "By State"
ActiveWorkbook.PivotCaches .Create(So urceType:= xlExternal , SourceData:= _
ActiveWorkbook.Connections ("ThisWork bookDataMo del"), Version:=6). _
CreatePivotTable TableDestination:="By State!R1C1", TableName:= _
"PivotTable1", DefaultVersion:=6
Cells(1, 1).Select
Sheets("By State").Select
Sheets("BillingFinal").Sel
Worksheets.Add
set WSname = ActiveSheet.name
WSname.Select
WSname.name = "By State"
ActiveWorkbook.PivotCaches
ActiveWorkbook.Connections
CreatePivotTable TableDestination:="By State!R1C1", TableName:= _
"PivotTable1", DefaultVersion:=6
Cells(1, 1).Select
Sheets("By State").Select
ASKER
ok It does not like the set statement.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
thanks
will do both; add a worksheet and select it.
To get the name you can use
Worksheets.add
wsname= activesheet.name