Reputation: 5261
Im using a pivot table to arrange my data. when I copy my data to another sheet its looks like that:
but I want the data to be one by the other like that:
how can I use the bold lines as headers and cut only the required ranges which are not fixed? I tried using macros but I could only copy fixed ranges so I'm doing it manually each time (and some om the sheets are pretty big). please help, thank you.
Upvotes: 1
Views: 95
Reputation:
You have full control on all the cells in the PivotTable
. Sample code:
Dim curpivottable As PivotTable
Set curpivottable = ActiveSheet.PivotTables(1)
Dim curRange As Range
Set curRange = curpivottable.TableRange1
For Each cell In curRange.Cells
If (cell.Font.Bold) Then
'This is a bold cell
End If
Next cell
Bear in mind that curRange
includes all the contents in curpivottable
, from the first row (where the title is).
-- UPDATE
My answer above was the generic way to deal with ranges in PivotTables. If all what you want is just copying/pasting a range, you can do it directly (is the same if the range is in the PivotTable or not). Example:
Dim origRange As Range
Set origRange = Sheets("Sheet1").Range("A2:A500")
Dim destRange As Range
Set destRange = Sheets("Sheet2").Range("A2")
origRange.Copy
destRange.PasteSpecial xlPasteValues
Equivalently, you can check the format of the given cells (being bold or not) independently upon being inside a PivotTable or not.
Upvotes: 1