How to create a worksheet in new workbook

sridharkk

New Member
Joined
Oct 6, 2005
Messages
11
How do we create a worksheet in new workbook

Dim wb As Workbook
Set wb = Workbooks.Add(xlWBATWorksheet)
wb.Worksheets(1).Name = "Pay-Per-Click"
wb.Sheets.Add (xlWorksheet)
wb.Worksheets(2).Name = "Categories"

This returns an error back Application Defined - Object Defined error

Thanks,
Sridhar
 

Excel Facts

Create a Pivot Table on a Map
If your data has zip codes, postal codes, or city names, select the data and use Insert, 3D Map. (Found to right of chart icons).
Code:
dim wb as workbook, ws as worksheet
set wb = workbooks.add(xlWBATWorksheet)
set ws = wb.sheets.add
ws.name ="Categories

This should do what you want.

HTH
Cal
 
Upvote 0
try this

Code:
Sub test()
Dim wb As Workbook
Set wb = Workbooks.Add(xlWBATWorksheet)
wb.Worksheets(1).Name = "Pay-Per-Click"
wb.Sheets.Add After:=Worksheets(Worksheets.Count)
wb.Worksheets(2).Name = "Categories"
End Sub
 
Upvote 0
Sub myWBAdd()
'Standard Module code, like: Module1
Dim myShCount%

Workbooks.Add
For Each Sh In Worksheets
myShCount = myShCount + 1
Next Sh

Sheets.Add
ActiveSheet.Name = "Tests"

Sheets("Tests").Move After:=Sheets(myShCount + 1)
Range("A1").Select
End Sub

Sub myWBAddOnly()
'Standard Module code, like: Module1

Workbooks.Add
Sheets.Add
ActiveSheet.Name = "Tests"

For Each Sh In Worksheets
If Sh.Name <> "Tests" Then Sh.Delete
Next Sh
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,641
Messages
6,120,684
Members
448,977
Latest member
dbonilla0331

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top