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

Move date out one month or year
Use =EDATE(A2,1) for one month later. Use EDATE(A2,12) for one year later.
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,214,636
Messages
6,120,669
Members
448,977
Latest member
moonlight6

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