hi,
I have this macro:
ub MoveData()
Dim LR As Long, LR2 As Long, LC As Long, Ctr As Long, NR As Long, ToMove As Long, RptLR As Long
Dim wks As Worksheet
Application.ScreenUpdating = False
Sheets(1).Select
On Error Resume Next
Sheets("Report").Select
If Err Then Worksheets.Add.Name = "Report"
On Error GoTo 0
With Sheets("Report")
.Range("A1").Resize(, 11).Value = [{"DIV","Line","Region","Area","SubArea","CountryCode","Country","Channel","TXN CUR","Type","Value"}]
RptLR = .Cells(Rows.Count, 1).End(xlUp).Row
If RptLR > 1 Then
.Range("A2:AC" & RptLR).ClearContents
End If
End With
For Each wks In ThisWorkbook.Worksheets
If wks.Name<> "Instructions" And wks.Name<> "Report" Then
With wks
.Select
LC = .Cells.Find(What:="*", SearchDirection:=xlPrevious, SearchOrder:=xlByColumns).Column
LR = .Cells(Rows.Count, 1).End(xlUp).Row
.Cells(1, LC + 2).Resize(, 11).Value = [{"DIV","Line","Region","Area","SubArea","CountryCode","Country","Channel","TXN CUR","Type","Value"}]
ToMove = LC - 1
For Ctr = 2 To LR Step 1
NR = .Cells(Rows.Count, LC + 2).End(xlUp).Row
.Range("A" & Ctr).Copy .Range(Cells(NR + 1, LC + 2), Cells(NR + ToMove - 8, LC + 2))
.Range("B" & Ctr).Copy .Range(Cells(NR + 1, LC + 3), Cells(NR + ToMove - 8, LC + 3))
.Range("C" & Ctr).Copy .Range(Cells(NR + 1, LC + 4), Cells(NR + ToMove - 8, LC + 4))
.Range("D" & Ctr).Copy .Range(Cells(NR + 1, LC + 5), Cells(NR + ToMove - 8, LC + 5))
.Range("E" & Ctr).Copy .Range(Cells(NR + 1, LC + 6), Cells(NR + ToMove - 8, LC + 6))
.Range("F" & Ctr).Copy .Range(Cells(NR + 1, LC + 7), Cells(NR + ToMove - 8, LC + 7))
.Range("G" & Ctr).Copy .Range(Cells(NR + 1, LC + 8), Cells(NR + ToMove - 8, LC + 8))
.Range("H" & Ctr).Copy .Range(Cells(NR + 1, LC + 9), Cells(NR + ToMove - 8, LC + 9))
.Range("I" & Ctr).Copy .Range(Cells(NR + 1, LC + 10), Cells(NR + ToMove - 8, LC + 10))
.Range(Cells(1, 10), Cells(1, LC)).Copy
With .Cells(NR + 1, LC + 11)
.PasteSpecial Paste:=xlPasteAll, Operation:=xlNone, SkipBlanks:=False, Transpose:=True
End With
.Range(Cells(Ctr, 10), Cells(Ctr, LC)).Copy
With .Cells(NR + 1, LC + 12)
.PasteSpecial Paste:=xlPasteAll, Operation:=xlNone, SkipBlanks:=False, Transpose:=True
End With
Next Ctr
LR2 = .Cells(Rows.Count, LC + 2).End(xlUp).Row
RptLR = Sheets("Report").Cells(Rows.Count, 1).End(xlUp).Row
.Range(Cells(2, LC + 2), Cells(LR2, LC + 12)).Copy Sheets("Report").Range("A" & RptLR + 1)
.Range(Cells(1, LC + 2), Cells(LR2, LC + 100)).ClearContents
.Range("A1").Select
Application.CutCopyMode = False
End With
End If
Next wks
Sheets("Report").Select
RptLR = Cells(Rows.Count, 1).End(xlUp).Row
Range("A1:AC" & RptLR).Columns.AutoFit
Range("K1").Select
Application.ScreenUpdating = True
End Sub
when I run it, it duplicates everything. I have a file with several tabs, all identical in format. I need to be able to go from:
Excel 2007
Basically I need to take a horizontal table and make it pivotable. Can anyone edit the macro? It worked before, but for some reason it doesn't now.
Thanks in advance for your help!
Rio
I have this macro:
ub MoveData()
Dim LR As Long, LR2 As Long, LC As Long, Ctr As Long, NR As Long, ToMove As Long, RptLR As Long
Dim wks As Worksheet
Application.ScreenUpdating = False
Sheets(1).Select
On Error Resume Next
Sheets("Report").Select
If Err Then Worksheets.Add.Name = "Report"
On Error GoTo 0
With Sheets("Report")
.Range("A1").Resize(, 11).Value = [{"DIV","Line","Region","Area","SubArea","CountryCode","Country","Channel","TXN CUR","Type","Value"}]
RptLR = .Cells(Rows.Count, 1).End(xlUp).Row
If RptLR > 1 Then
.Range("A2:AC" & RptLR).ClearContents
End If
End With
For Each wks In ThisWorkbook.Worksheets
If wks.Name<> "Instructions" And wks.Name<> "Report" Then
With wks
.Select
LC = .Cells.Find(What:="*", SearchDirection:=xlPrevious, SearchOrder:=xlByColumns).Column
LR = .Cells(Rows.Count, 1).End(xlUp).Row
.Cells(1, LC + 2).Resize(, 11).Value = [{"DIV","Line","Region","Area","SubArea","CountryCode","Country","Channel","TXN CUR","Type","Value"}]
ToMove = LC - 1
For Ctr = 2 To LR Step 1
NR = .Cells(Rows.Count, LC + 2).End(xlUp).Row
.Range("A" & Ctr).Copy .Range(Cells(NR + 1, LC + 2), Cells(NR + ToMove - 8, LC + 2))
.Range("B" & Ctr).Copy .Range(Cells(NR + 1, LC + 3), Cells(NR + ToMove - 8, LC + 3))
.Range("C" & Ctr).Copy .Range(Cells(NR + 1, LC + 4), Cells(NR + ToMove - 8, LC + 4))
.Range("D" & Ctr).Copy .Range(Cells(NR + 1, LC + 5), Cells(NR + ToMove - 8, LC + 5))
.Range("E" & Ctr).Copy .Range(Cells(NR + 1, LC + 6), Cells(NR + ToMove - 8, LC + 6))
.Range("F" & Ctr).Copy .Range(Cells(NR + 1, LC + 7), Cells(NR + ToMove - 8, LC + 7))
.Range("G" & Ctr).Copy .Range(Cells(NR + 1, LC + 8), Cells(NR + ToMove - 8, LC + 8))
.Range("H" & Ctr).Copy .Range(Cells(NR + 1, LC + 9), Cells(NR + ToMove - 8, LC + 9))
.Range("I" & Ctr).Copy .Range(Cells(NR + 1, LC + 10), Cells(NR + ToMove - 8, LC + 10))
.Range(Cells(1, 10), Cells(1, LC)).Copy
With .Cells(NR + 1, LC + 11)
.PasteSpecial Paste:=xlPasteAll, Operation:=xlNone, SkipBlanks:=False, Transpose:=True
End With
.Range(Cells(Ctr, 10), Cells(Ctr, LC)).Copy
With .Cells(NR + 1, LC + 12)
.PasteSpecial Paste:=xlPasteAll, Operation:=xlNone, SkipBlanks:=False, Transpose:=True
End With
Next Ctr
LR2 = .Cells(Rows.Count, LC + 2).End(xlUp).Row
RptLR = Sheets("Report").Cells(Rows.Count, 1).End(xlUp).Row
.Range(Cells(2, LC + 2), Cells(LR2, LC + 12)).Copy Sheets("Report").Range("A" & RptLR + 1)
.Range(Cells(1, LC + 2), Cells(LR2, LC + 100)).ClearContents
.Range("A1").Select
Application.CutCopyMode = False
End With
End If
Next wks
Sheets("Report").Select
RptLR = Cells(Rows.Count, 1).End(xlUp).Row
Range("A1:AC" & RptLR).Columns.AutoFit
Range("K1").Select
Application.ScreenUpdating = True
End Sub
when I run it, it duplicates everything. I have a file with several tabs, all identical in format. I need to be able to go from:
Excel Workbook | ||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
A | B | C | D | E | F | G | H | I | J | K | L | |||
1 | Div. | Line | Region | Area | Sub-Area | Ctry. Code | Ctry. | CHAN | TXN CUR | Apr Units | May Units | Jun Units | ||
2 | 201 | EMBO | CHINA | CHINA | CHINA | CH | China | DS | RMB | - | - | - | ||
3 | 201 | BIPOLAR | CHINA | CHINA | CHINA | CH | China | DS | RMB | - | - | - | ||
4 | 201 | BIOTRAY | CHINA | CHINA | CHINA | CH | China | DS | RMB | - | - | - | ||
5 | 201 | CVC | CHINA | CHINA | CHINA | CH | China | DS | RMB | 6,700 | 6,850 | 8,100 | ||
201JWIC |
#VALUE!
Basically I need to take a horizontal table and make it pivotable. Can anyone edit the macro? It worked before, but for some reason it doesn't now.
Thanks in advance for your help!
Rio