bulk add worksheets from list of names

supper's ready

New Member
Joined
Jun 3, 2011
Messages
23
Hello,

i want to be able to bulk add new worksheets named after a list of names.
lets say the worksheets to add will be in a2:a16 though i won't necessarily have all the cells filled (maybe sometimes im only adding one).

in addition, for each worksheet added i will be defining a variable as a column address in b2:b16. This should be defined within a newly generated if statement

example:
Column A Column B
Nameofsheet B

results:
this will create a sheet named nameofsheet and also add some code like:

If Sheet.Name = "Nameofsheet" Then
Columns("B:B").Select
Selection.NumberFormat = "m/d/yyyy"
dtMin = WorksheetFunction.Min(Columns("B:B"))
dtMax = WorksheetFunction.Max(Columns("B:B"))
DayMin = Day(dtMin)
DayMax = Day(dtMax)
End If

this is static other than the column entered in column B and Sheet.Name

Thank you :biggrin:
 

Excel Facts

VLOOKUP to Left?
Use =VLOOKUP(A2,CHOOSE({1,2},$Z$1:$Z$99,$Y$1:$Y$99),2,False) to lookup Y values to left of Z values.
Try this on a copy of your data but it should create a new sheet for every entry in Column A
Code:
Sub CreateSheetPerLine()

   Application.ScreenUpdating = False
   Dim LR As Long, i As Long
LR = Range("A" & Rows.Count).End(xlUp).Row
Sheets("Sheet1").Select 'change to name of your sheet
For i = 1 To LR Step 1
    If Range("A" & i).Value <> "" Then Rows(i).Select
    Selection.Copy
    Sheets.Add after:=Sheets(Sheets.Count)
    With ActiveSheet
    Range("A1").Select
    Selection.PasteSpecial Paste:=xlPasteAll, Operation:=xlNone, SkipBlanks:= _
        False, Transpose:=True
    Application.CutCopyMode = False
    ActiveSheet.Name = Range("A1")
    Columns("A:A").AutoFit
    Cells(Rows.Count, "A").End(xlUp).Offset(1).Select
    Range(Selection, Selection.End(xlDown)).Select
    With Selection.Interior
        .Pattern = xlNone
        .TintAndShade = 0
        .PatternTintAndShade = 0
    End With
    Range("A1").Select
    End With
    Sheets("Sheet1").Select
    Next i
    Application.ScreenUpdating = True
End Sub
 
Upvote 0
wow thats a lot of code.
i actually managed to get that part done with:

Code:
Sub MakeSheets()

Dim ListofNames As Range
Dim c As Range

Set ListofNames = ActiveSheet.[B10:B24]

For Each c In ListofNames
If c.Text <> vbNullString Then
On Error GoTo InvalidName
ThisWorkbook.Sheets.Add After:=Sheets(Sheets.Count)
ActiveSheet.Name = c.Value
NextC:
End If
Next

Exit Sub

InvalidName:
MsgBox """" & c.Value & """ is an invalid sheet name.", vbOKOnly + vbCritical, "Add Sheets"
Resume NextC

End Sub

i still need to figure out how to add the if statement for each sheet to be added. Im not even sure if this is possible???
 
Last edited:
Upvote 0

Forum statistics

Threads
1,224,522
Messages
6,179,297
Members
452,903
Latest member
Knuddeluff

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