Do the headings actually repeat like in your first example?
Sub Test()
Dim ShNew As Worksheet
Dim LastRow As Long
Dim First As Long
Dim r As Long
Dim i As Long
Set ShNew = Worksheets.Add
ShNew.Range("A1:I1").Value = Array("Act. per 8", "Plan. per 8", "Var. per 8", "Cost center", "Cost center text", "Cost element", "Cost element text", "Act per 01 - 8", "Plan version 3")
First = 2
r = 2
With Worksheets("Sheet1")
LastRow = .Range("A" & .Rows.Count).End(xlUp).Row
For i = 2 To LastRow
If Left(.Range("D" & i).Value, 1) <> "*" Then
.Range("A" & i).Resize(, 3).Copy ShNew.Range("A" & r)
ShNew.Range("F" & r).Value = Left(.Range("D" & i).Value, 6)
ShNew.Range("G" & r).Value = Mid(.Range("D" & i).Value, 8)
.Range("E" & i).Resize(, 2).Copy ShNew.Range("H" & r)
r = r + 1
Else
ShNew.Range("D" & First & ":D" & r - 1).Value = Mid(Trim(.Range("D" & i).Value), 3, 5)
ShNew.Range("E" & First & ":E" & r - 1).Value = Mid(Trim(.Range("D" & i).Value), 9)
First = r
End If
Next i
End With
End Sub
Excel 2010 | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
A | B | C | D | E | F | G | H | I | |||
1 | Act. per 8 | Plan. per 8 | Var. per 8 | Cost center | Cost center text | Cost element | Cost element text | Act per 01 - 8 | Plan version 3 | ||
2 | 1769 | 41666.66 | -39897.66 | 19065 | Customer magazines | 591202 | Customer magazines. production | 453677 | 500000 | ||
3 | -140 | 0 | -140 | 19065 | Customer magazines | 591816 | Customer magazines | -2520 | 0 | ||
4 | 0 | 0 | 0 | 19065 | Customer magazines | 625001 | Postal expenses | -1499990.5 | 0 | ||
5 | 0 | 0 | 0 | 19065 | Customer magazines | 655901 | Other consultant fees | 217271 | 0 | ||
6 | 148 | 0 | 148 | 19065 | Customer magazines | 659202 | Hired Services Elanders (Publ Store) | 752 | 0 | ||
7 | 0 | 0 | 0 | 19066 | VT Press Test | 564901 | Demo/test vehicle miscellaneous | 107138 | 0 | ||
8 | 0 | 4166.66 | -4166.66 | 19067 | VT Advertising | 591101 | Daily press media space | 0 | 50000 | ||
9 | 0 | 41666.66 | -41666.66 | 19067 | VT Advertising | 591201 | Magazine media space | 329504.25 | 500000 | ||
10 | 0 | 0 | 0 | 19067 | VT Advertising | 591802 | Advertising | 10000 | 0 | ||
11 | 0 | 0 | 0 | 19067 | VT Advertising | 595002 | POS production | 13158 | 0 | ||
12 | 0 | 0 | 0 | 19067 | VT Advertising | 597102 | Photos production | 1500 | 0 | ||
13 | 0 | 4583.34 | -4583.34 | 19067 | VT Advertising | 597401 | Internet | 0 | 55000 | ||
14 | 0 | 8333.34 | -8333.34 | 19067 | VT Advertising | 599701 | Other advertising costs | 136700 | 100000 | ||
15 | 0 | 8333.34 | -8333.34 | 19067 | VT Advertising | 615001 | Printed matter | 11406 | 100000 | ||
16 | 0 | 2083.34 | -2083.34 | 19069 | VT PR/Media | 564901 | Demo/test vehicle miscellaneous | 25120 | 25000 | ||
17 | 0 | 0 | 0 | 19069 | VT PR/Media | 581003 | Tickets other countries | 0 | 0 | ||
18 | 14290 | 1250 | 13040 | 19069 | VT PR/Media | 597102 | Photos production | 14290 | 15000 | ||
19 | 0 | 28750 | -28750 | 19069 | VT PR/Media | 598401 | Sponsorship | 326058.2 | 345000 | ||
20 | 0 | 0 | 0 | 19069 | VT PR/Media | 609801 | Other sales costs | 173.41 | 0 | ||
21 | 25119.13 | 0 | 25119.13 | 19069 | VT PR/Media | 783501 | Depreciation of cars | 25119.13 | 0 | ||
Sheet4 |
Sub Test()
Dim ShNew As Worksheet
Dim LastRow As Long
Dim First As Long
Dim r As Long
Dim i As Long
Set ShNew = Worksheets.Add
ShNew.Range("A1:I1").Value = Array("Act. per 8", "Plan. per 8", "Var. per 8", "Cost center", "Cost center text", "Cost element", "Cost element text", "Act per 01 - 8", "Plan version 3")
First = 2
r = 2
With Worksheets("Sheet1")
LastRow = .Range("A" & .Rows.Count).End(xlUp).Row
For i = 2 To LastRow
If Left(.Range("D" & i).Value, 1) <> "*" Then
.Range("A" & i).Resize(, 3).Copy ShNew.Range("A" & r)
ShNew.Range("F" & r).Value = Left(WorksheetFunction.Trim(.Range("D" & i).Value), 6)
ShNew.Range("G" & r).Value = Mid(WorksheetFunction.Trim(.Range("D" & i).Value), 8)
.Range("E" & i).Resize(, 2).Copy ShNew.Range("H" & r)
r = r + 1
Else
ShNew.Range("D" & First & ":D" & r - 1).Value = Mid(WorksheetFunction.Trim(.Range("D" & i).Value), 3, 5)
ShNew.Range("E" & First & ":E" & r - 1).Value = Mid(WorksheetFunction.Trim(.Range("D" & i).Value), 9)
First = r
End If
Next i
End With
End Sub