Create Multiple Sheets based on the cell value through VBA
Sub Addsheet()
'Declaring the Variables
'Declaring the Variables
Dim i As Integer
Dim LastRow As Integer
'Finding Last Row in Sheet1
'Finding Last Row in Sheet1
LastRow = Worksheets("Sheet1").Cells(Worksheets("Sheet1").Rows.Count, "A").End(xlUp).Row
'Using For Loop to Add Sheets by Cell Value
'Using For Loop to Add Sheets by Cell Value
For i = 1 To LastRow
Sheets.Add
ActiveSheet.Name = Worksheets("Sheet1").Cells(i, 1).Value
Next i
End Sub
Lets Discuss the above code:
- We have defined two variable "i" and "LastRow".
- LastRow find the the row in "Sheet1" from Column "A". Because the list of sheets names are stored in "A" column in "Sheet1".
- We have used for loop to create multiple sheets untill all the sheets are created.
You can watch below video in action.
I noticed when I run this in larger files the order of sheets is re-arranged.
ReplyDeleteEG if my current work book has sheets "ABC" , "DEF" , "GHI". and I run this VBA output is
"ABC" ,"NEWsheet2", "DEF" ,"NEWsheet1", "GHI". or some random order.
I would like it to output
"ABC" , "DEF" , "GHI" ,"NEWsheet1" ,"NEWsheet2" .... and so on.
How can that be possible?
Hi,
ReplyDeleteThak you for this code!
The code is working and I need in every new sheet to be the data fro the hole row and when we add new data in sell to create only the new sheet.
Can you help me please
10x