MarkAndrews
Well-known Member
- Joined
- May 2, 2006
- Messages
- 1,970
- Office Version
- 2010
- Platform
- Windows
I need some help with some code
I have a sheet populated in columns A:N (Named “PPR Dump”)
Row 1 contains column headings
Column D contains a Stock_Code
What I need to do I create a macro which looks at Column D then
1. Creates a new sheet for each code in this column (Unique)
2. Pastes all columns relevant to that stock code and all occurances onto the appropriate sheet (Keeping the original data on “PPR Dump”)
I tried editing the following code, but I am stumped!
Thanks in advance
I have a sheet populated in columns A:N (Named “PPR Dump”)
Row 1 contains column headings
Column D contains a Stock_Code
What I need to do I create a macro which looks at Column D then
1. Creates a new sheet for each code in this column (Unique)
2. Pastes all columns relevant to that stock code and all occurances onto the appropriate sheet (Keeping the original data on “PPR Dump”)
I tried editing the following code, but I am stumped!
Option Explicit
Sub Unique()
Dim lngLastRow As Long, lngCalc As Long
Dim rngCustomerNumbers As Range, rngCell As Range
With Application
.ScreenUpdating = False
.EnableEvents = False
lngCalc = .Calculation
.Calculation = xlManual
End With
With Sheets("PPR DUMP")
lngLastRow = .Range("D" & Rows.Count).End(xlUp).Row
Set rngCustomerNumbers = .Range("D1:A" & lngLastRow)
End With
With Sheets("Unique")
lngLastRow = .Range("A" & Rows.Count).End(xlUp).Row
.Range("A1:A" & lngLastRow).Clear
rngCustomerNumbers.AdvancedFilter xlFilterCopy, , .Range("D1"), True
lngLastRow = .Range("A" & Rows.Count).End(xlUp).Row
On Error Resume Next
For Each rngCell In .Range("A2:A" & lngLastRow)
With Sheets("Master")
.AutoFilterMode = False
Sheets.Add(, Sheets(Sheets.Count)).Name = rngCell.Value
lngLastRow = .Range("D" & Rows.Count).End(xlUp).Row
With .Range("D1:A" & lngLastRow)
.AutoFilter field:=1, Criteria1:=rngCell.Value
.EntireRow.Copy ActiveSheet.Range("D1")
.AutoFilter
End With
End With
Next rngCell
On Error GoTo 0
End With
With Application
.ScreenUpdating = True
.EnableEvents = True
.Calculation = lngCalc
End With
Sheets("Unique").Activate
MsgBox "Excel has added " & Worksheets.Count - 2 & " New worksheets"
Set rngCustomerNumbers = Nothing
Set rngCell = Nothing
End Sub
Thanks in advance