Hi Guys, I hope I might get some help in this form in regards to what i am trying to achieve, Create New Workbook for each cell value and then name each new work book with 2 cell values.
So on the below code it does the job of creating new work book from each cell, but i would like to name the new work book automatically with a the cell name used to split the work book.
Any help in here is appreciated.
Sub CopyInNewWB()
Dim wbO As Workbook, wbN As Workbook
Dim xRCount As Long
Dim xSht As Worksheet
Dim xNSht As Worksheet
Dim I As Long
Dim xTRrow As Integer
Dim xCol As New Collection
Dim xTitle As String
Dim xSUpdate As Boolean
Dim xCName As Integer
Dim xTA, xRA, xSRg1 As String
Set xSht = ThisWorkbook.Worksheets("Template")
On Error Resume Next
Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual
Application.DisplayAlerts = False
xRCount = xSht.Cells(xSht.Rows.Count, 1).End(xlUp).Row
xTitle = "A:K"
xCName = "2" 'Change this number to the column number which you will create new sheets based on
xTRrow = xSht.Range(xTitle).Cells(1).Row
For I = 2 To xRCount
Call xCol.Add(xSht.Cells(I, xCName).Text, xSht.Cells(I, xCName).Text)
Next
xSUpdate = Application.ScreenUpdating
Application.ScreenUpdating = False
xSRg = xSht.Cells(1, xCName).Address(RowAbsolute:=False, ColumnAbsolute:=False)
For I = 1 To xCol.Count
Set wbN = Workbooks.Add
ThisWorkbook.Sheets("CoverPage").Copy After:=Sheets(Sheets.Count)
Call xSht.Range(xTitle).AutoFilter(xCName, CStr(xCol.Item(I)))
Set xNSht = Nothing
Set xNSht = Worksheets(CStr(xCol.Item(I)))
If xNSht Is Nothing Then
Set xNSht = Worksheets.Add(, Sheets(Sheets.Count))
wbN.Sheets("Sheet1").Delete
xNSht.Name = CStr(xCol.Item(I))
ActiveWindow.DisplayGridlines = False
Else
xNSht.Move , Sheets(Sheets.Count)
End If
xSht.Range("A" & xTRrow & ":A" & xRCount).EntireRow.Copy xNSht.Range("A1")
xNSht.Columns.AutoFit
Next
With ActiveWorkbook
For Each lnk In .LinkSources(Type:=xlLinkTypeExcelLinks)
.BreakLink Name:=lnk, Type:=xlLinkTypeExcelLinks
Next
End With
xSht.AutoFilterMode = False
xSht.Activate
Application.ScreenUpdating = xSUpdate
Sheets("ReportH").Activate
Call Sheets("ReportH").ForceClickOnBouttonXYZ
Application.ScreenUpdating = True
Application.Calculation = xlCalculationAutomatic
Application.DisplayAlerts = True
ErrHandler:
Application.ScreenUpdating = True
Application.Calculation = xlCalculationAutomatic
Application.DisplayAlerts = True
End Sub
So on the below code it does the job of creating new work book from each cell, but i would like to name the new work book automatically with a the cell name used to split the work book.
Any help in here is appreciated.
Sub CopyInNewWB()
Dim wbO As Workbook, wbN As Workbook
Dim xRCount As Long
Dim xSht As Worksheet
Dim xNSht As Worksheet
Dim I As Long
Dim xTRrow As Integer
Dim xCol As New Collection
Dim xTitle As String
Dim xSUpdate As Boolean
Dim xCName As Integer
Dim xTA, xRA, xSRg1 As String
Set xSht = ThisWorkbook.Worksheets("Template")
On Error Resume Next
Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual
Application.DisplayAlerts = False
xRCount = xSht.Cells(xSht.Rows.Count, 1).End(xlUp).Row
xTitle = "A:K"
xCName = "2" 'Change this number to the column number which you will create new sheets based on
xTRrow = xSht.Range(xTitle).Cells(1).Row
For I = 2 To xRCount
Call xCol.Add(xSht.Cells(I, xCName).Text, xSht.Cells(I, xCName).Text)
Next
xSUpdate = Application.ScreenUpdating
Application.ScreenUpdating = False
xSRg = xSht.Cells(1, xCName).Address(RowAbsolute:=False, ColumnAbsolute:=False)
For I = 1 To xCol.Count
Set wbN = Workbooks.Add
ThisWorkbook.Sheets("CoverPage").Copy After:=Sheets(Sheets.Count)
Call xSht.Range(xTitle).AutoFilter(xCName, CStr(xCol.Item(I)))
Set xNSht = Nothing
Set xNSht = Worksheets(CStr(xCol.Item(I)))
If xNSht Is Nothing Then
Set xNSht = Worksheets.Add(, Sheets(Sheets.Count))
wbN.Sheets("Sheet1").Delete
xNSht.Name = CStr(xCol.Item(I))
ActiveWindow.DisplayGridlines = False
Else
xNSht.Move , Sheets(Sheets.Count)
End If
xSht.Range("A" & xTRrow & ":A" & xRCount).EntireRow.Copy xNSht.Range("A1")
xNSht.Columns.AutoFit
Next
With ActiveWorkbook
For Each lnk In .LinkSources(Type:=xlLinkTypeExcelLinks)
.BreakLink Name:=lnk, Type:=xlLinkTypeExcelLinks
Next
End With
xSht.AutoFilterMode = False
xSht.Activate
Application.ScreenUpdating = xSUpdate
Sheets("ReportH").Activate
Call Sheets("ReportH").ForceClickOnBouttonXYZ
Application.ScreenUpdating = True
Application.Calculation = xlCalculationAutomatic
Application.DisplayAlerts = True
ErrHandler:
Application.ScreenUpdating = True
Application.Calculation = xlCalculationAutomatic
Application.DisplayAlerts = True
End Sub