Hi all
I have toiled and toiled with this hence the name I chose.
Basically I produce an excel sheet each month, in column A is a Id, this Id can be repeated for several rows (varies) - what I need to do is create new workbooks for each Id and pull the data from the original table through too, so create new work books based on that Id and the corresponding info
I could do filters etc for each of the known Ids (about 127) and then copy this into a new sheet but it would be messy and very rough code based on recording and trial and error
I found this code which can create new workbooks for each of the Ids,
can anyone help pulling through the data? at the moment its populating the field names only from the top of the document
Option Explicit
Sub CreateWorkbooks()
Dim strMyPath As String
Dim wkbNew As Workbook
Dim wksNew As Worksheet
Dim rUniqueVals As Range
Dim rCell As Range
Dim LastRow As Long
Dim LastColumn As Long
With ActiveSheet.UsedRange
LastRow = .Rows.Count + .Rows(1).Row - 1
LastColumn = .Columns.Count + .Columns(1).Column - 1
End With
If LastRow > 1 Then
Application.ScreenUpdating = False
strMyPath = "\\my file for the docs to be created"
If Right(strMyPath, 1) <> "\" Then strMyPath = strMyPath & "\"
With Range(Cells(1, 1), Cells(LastRow, LastColumn))
.Sort key1:=Range("A1"), Order1:=xlAscending, Header:=xlYes, _
ordercustom:=1, MatchCase:=False, Orientation:=xlTopToBottom
End With
Range("A1:A" & LastRow).AdvancedFilter xlFilterInPlace, , , True
Set rUniqueVals = Range("A2:A" & LastRow).SpecialCells(xlCellTypeVisible)
For Each rCell In rUniqueVals
With ActiveSheet.UsedRange
.AutoFilter Field:=5, Criteria1:=rCell.Value
.Copy
End With
Set wkbNew = Workbooks.Add(xlWBATWorksheet)
Set wksNew = wkbNew.Worksheets(1)
wksNew.Range("A1").PasteSpecial
wkbNew.SaveAs strMyPath & rCell.Value & ".xlsx", 51
wkbNew.Close False
Next rCell
ActiveSheet.ShowAllData
Application.ScreenUpdating = True
MsgBox "Completed...", vbInformation
Else
MsgBox "No data is available...", vbExclamation
End If
End Sub
Thanks guys, would help me a lot
Bookmarks