1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61
| Sub save()
Dim test As Range
Dim cell_des As Range
Dim table() As String
Dim j As Integer
With Worksheets("contacts_archiv")
Set test = .Range("A1")
For i = 1 To .Columns(1).Find("*", , , , xlByColumns, xlPrevious).Row - 1
ReDim table(1 To 1)
If test.Offset(i, 0) <> test.Offset(i - 1, 0) Then
j = 0
Do
ReDim Preserve table(1 To j + 1)
table(j + 1) = test.Offset(i + j, 1).Value
j = j + 1
Loop Until test.Offset(i + j, 0).Value <> test.Offset(i, 0).Value
AddNewWorkbook test.Offset(i, 0), table
End If
Next i
End With
End Sub
Function AddNewWorkbook(rng As Range, table() As String)
Dim xlApp As Excel.Application
Dim workb As Workbook
Dim xlSheet As Excel.Worksheet
Dim strt As Integer
Dim cell_des As Range
Dim msg As String
Set xlApp = CreateObject("Excel.Application")
xlApp.SheetsInNewWorkbook = 1
Set workb = Application.Workbooks.Add
workb.SaveAs Filename:=rng.Offset(0, 2).Value
xlApp.Visible = True
Set xlSheet = workb.Worksheets(1)
xlSheet.name = rng.Value
With ActiveWorkbook.Worksheets(rng.Value)
Set cell_des = .Range("A1")
cell_des = "Contact"
cell_des.Font.Bold = True
cell_des.Offset(0, 1) = "Infos"
cell_des.Offset(0, 1).Font.Bold = True
For i = 1 To UBound(table)
cell_des.Offset(i, 0) = rng.Value
cell_des.Offset(i, 1) = table(i)
Next i
End With
ActiveWorkbook.Close SaveChanges:=True
xlApp.Quit
End Function |
Partager