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
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: