Need to create new sheets with names from Array

mpatino

Board Regular
Joined
Jul 8, 2009
Messages
82
Hi Experts,

I need to create new worksheets using the names stored in an Array, however, when I run my code it creates the right amount of sheets, but the names are not been assigned to the new worksheets, so I was wondering if one of you could point my mistake, below is my code:

Sub createSheets()


Dim WsName As Variant
Dim WsNames() As Variant
Dim ws As Worksheet
Dim i As Variant

WsNames() = Array("ABC", "BCD", "CDE", "DEF", "EFG")


i = i + 1

For Each WsName In WsNames()
Set ws = ThisWorkbook.Sheets.Add(After:= _
ThisWorkbook.Sheets(ThisWorkbook.Sheets.Count))
WsName = WsNames(i)


Next WsName

End Sub
 
Last edited:

Excel Facts

Why does 9 mean SUM in SUBTOTAL?
It is because Sum is the 9th alphabetically in Average, Count, CountA, Max, Min, Product, StDev.S, StDev.P, Sum, VAR.S, VAR.P.
Try:
Code:
Sub createSheets()
    Application.ScreenUpdating = False
    Dim WsNames As Variant
    Dim i As Long
    WsNames = Array("ABC", "BCD", "CDE", "DEF", "EFG")
    For i = LBound(WsNames) To UBound(WsNames)
        Sheets.Add(After:=Sheets(Sheets.Count)).Name = WsNames(i)
    Next i
    Application.ScreenUpdating = True
End Sub
 
Upvote 0
You are very welcome and thank you for the feedback. :)
 
Upvote 0

Forum statistics

Threads
1,223,250
Messages
6,171,036
Members
452,374
Latest member
keccles

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