This works:
Option Base 1
Option Explicit
Sub SplitSalesData()
Dim DataArray(50000, 3) As Variant
Dim fnd As Double
Dim x As Double
Dim y As Double
Dim SlsPeople(500, 2) As Variant
Dim Sls As Double
Dim Found As Integer
Dim Z As Double
Dim W As Double
Dim Locations(500, 2) As Variant
Dim NbrLoc As Double
Sheets("MainDataSheet").Select '<--Change name to what it is
x = 1
Do While True
If Cells(x, 1).Value = Empty Then Exit Do
Found = 0
For y = 1 To Sls
If SlsPeople(y, 1) = Cells(x, 2).Value Then
Found = 1
Exit For
End If
Next
If Found = 0 Then
Sls = Sls + 1
SlsPeople(Sls, 1) = Cells(x, 2).Value
SlsPeople(Sls, 2) = Cells(x, 1).Value
End If
Found = 0
For y = 1 To NbrLoc
If Locations(y, 1) = Cells(x, 1).Value Then
Found = 1
Exit For
End If
Next
If Found = 0 Then
NbrLoc = NbrLoc + 1
Locations(NbrLoc, 1) = Cells(x, 1).Value
End If
fnd = fnd + 1
For y = 1 To 3
DataArray(fnd, y) = Cells(x, y).Value
Next
x = x + 1
Loop
Dim MyEntries As String
Dim NewWks As Worksheet
For W = 1 To NbrLoc
Workbooks.Add Template:="Workbook"
MyEntries = ActiveWorkbook.Name
For y = 1 To Sls
If SlsPeople(y, 2) = Locations(W, 1) Then
Z = 1
Set NewWks = Worksheets.Add
NewWks.Name = SlsPeople(y, 1)
Cells(1, 1).Value = "Salesman"
Cells(1, 2).Value = "Amount"
For x = 1 To fnd
If DataArray(x, 2) = SlsPeople(y, 1) Then
Z = Z + 1
Cells(Z, 1).Value = DataArray(x, 2)
Cells(Z, 2).Value = DataArray(x, 3)
End If
Next
End If
Next
ActiveWorkbook.SaveAs Filename:="C:\TEMP\" & Locations(W, 1) & ".xlsx",
FileFormat:= _
xlOpenXMLWorkbook, CreateBackup:=False
Next
End Sub
"michael.beckinsale" wrote:
> Hi All,
>
> I have a table of data that looks some thing like this:
>
> Column A Column B Column C
> British Isles Salesman A 123
> British Isles Salesman A 345
> British Isles Salesman A 123456
> British Isles Salesman B 9876
> British Isles Salesman B 6789
> British Isles Salesman C 7532
> Europe Salesman 1 98475
> Europe Salesman 1 9692
> Europe Salesman 1 598310
> Europe Salesman 2 6533
> Europe Salesman 2 35678
> Europe Salesman 3 9643
> Europe Salesman 3 1423
> Europe Salesman 4 7643
> etc
>
> What l want to do is create the following using the data in the table:
>
> A workbook called 'Britsh Isles' with sheets for each salesman
> containing each row of data
> A workbook called 'Europe' with sheets for each salesman containing
> each row of data
>
> There will always be a variable number of Regions, Salesman & Data
> rows
>
> The workbooks should ideally be saved in the same directory as the
> originating workbook.
>
> Does anybody have any VBA code to achieve this or can they point me in
> the right direction please?
>
> All ideas gratefully received.
>
> Regards
>
> Michael
>
|