Loop through columns, create a workbook and sheets.

JonesZoid

New Member
Joined
Dec 11, 2013
Messages
27
I have a list of sitenames in column E and a list of racks in column C which are in the said sitename.

ABCDE
Rack ASite 1
Rack ASite 2
Rack BSite 2
Rack CSite 2
Rack ASite 3
Rack BSite 3

I would like to loop through column E and create a workbook for that site, the range will be in alphabetical order. Then use column C to create a worksheet in each workbook for each rack.

I can do all the data manipulation and transferring, just not sure how to do the above.

Any help would be greatly appreciated.
 

Excel Facts

When they said...
When they said you are going to "Excel at life", they meant you "will be doing Excel your whole life".
This macro assumes you have headers in row 1. Change the sheet name (in red) to suit your needs.
Rich (BB code):
Sub CreateWorkbooks()
    Application.ScreenUpdating = False
    Dim rack As Range, v As Variant, i As Long, srcWS As Worksheet, LastRow As Long
    Set srcWS = ThisWorkbook.Sheets("Sheet1")
    LastRow = srcWS.Cells.Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
    v = srcWS.Range("E2:E" & LastRow).Value
    With CreateObject("Scripting.Dictionary")
        For i = 1 To UBound(v, 1)
            If Not .Exists(v(i, 1)) Then
                .Add v(i, 1), Nothing
                srcWS.Range("E1:E" & LastRow).AutoFilter 1, v(i, 1)
                Workbooks.Add 1
                For Each rack In srcWS.Range("C2:C" & LastRow).SpecialCells(xlCellTypeVisible)
                    Sheets.Add(After:=Sheets(Sheets.Count)).Name = rack
                Next rack
            End If
        Next i
    End With
    srcWS.Range("E2").AutoFilter
    Application.ScreenUpdating = True
End Sub
 
Upvote 0
Solution
Thanks Mumps that nearly worked perfectly, had to adjust the autofilter to match column E, as you had it set to column A.

Otherwise great job, thanks again.
 
Upvote 0

Forum statistics

Threads
1,214,952
Messages
6,122,458
Members
449,085
Latest member
ExcelError

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