Hi All,
I am hoping someone on here can help me figure my issue out
I have tried searching the internet and tried a few solutions and I am nearly there but having an issue.
I have a spreadsheet (obviously) that contains a list of names in column B, I want to create a macro that will create a new workbook for each name and name the files as that name in the list and save in a specific folder. The list can vary in size from 140 to 250 entries and I don't want it to include the title of the list or blank cells.
The code I have created so far creates the workbooks from the list but includes the title of the list and attempts to create further workbooks from blank cells which prompts a message advising the file already exists, pressing no then aborts the macro with an error.
Any help would be greatly appreciated
Here is the code I have managed to piece together so far:
I am hoping someone on here can help me figure my issue out
I have tried searching the internet and tried a few solutions and I am nearly there but having an issue.
I have a spreadsheet (obviously) that contains a list of names in column B, I want to create a macro that will create a new workbook for each name and name the files as that name in the list and save in a specific folder. The list can vary in size from 140 to 250 entries and I don't want it to include the title of the list or blank cells.
The code I have created so far creates the workbooks from the list but includes the title of the list and attempts to create further workbooks from blank cells which prompts a message advising the file already exists, pressing no then aborts the macro with an error.
Any help would be greatly appreciated
Here is the code I have managed to piece together so far:
Code:
[SIZE=1]Private Sub CommandButton1_Click()[/SIZE]
[SIZE=1]Dim wb As Workbook[/SIZE]
[SIZE=1]Dim [/SIZE][SIZE=1]Sht[/SIZE][SIZE=1] As Worksheet[/SIZE]
[SIZE=1]Dim [/SIZE][SIZE=1]Lrow[/SIZE][SIZE=1] As Long[/SIZE]
[SIZE=1]Dim Rng As Range[/SIZE]
[SIZE=1]Dim Count As Long[/SIZE]
[SIZE=1]Dim [/SIZE][SIZE=1]wbName[/SIZE][SIZE=1] As String[/SIZE]
[SIZE=1]
[/SIZE]
[SIZE=1]Set wb = ThisWorkbook[/SIZE]
[SIZE=1]Set Sht = wb.Sheets(2)[/SIZE]
[SIZE=1]LRow = Sht.Cells(Rows.Count, "B").End(xlUp).Row[/SIZE]
[SIZE=1]Set Rng = Sht.Range("B3:B" & LRow)[/SIZE]
[SIZE=1]Count = 1[/SIZE]
[SIZE=1]
[/SIZE]
[SIZE=1] Do[/SIZE]
[SIZE=1] Count = Count + 1[/SIZE]
[SIZE=1] wbName = Sheet2.Range("B3" & Count).Value[/SIZE]
[SIZE=1] Workbooks.Open ("C:\My Documents\Template.xls")[/SIZE]
[SIZE=1] ActiveWorkbook.SaveAs FileName:="C:\My Documents\Archive\" & wbName & ".xls"[/SIZE]
[SIZE=1] ActiveWorkbook.Cloase False[/SIZE]
[SIZE=1] Loop Until Count = LRow[/SIZE]
[SIZE=1]End Sub[/SIZE]