98.7% Of all customers recommend us, we're so confident about our results we publish all reviews and stats
View Live Stats View ReviewsForum home » Delegate support and help forum » Microsoft Excel VBA Training and help » Diagonals on tables transposed to columns | Excel forum
Diagonals on tables transposed to columns | Excel forum
Resolved · Low Priority · Version 2007
Ben has attended:
Excel VBA Intro Intermediate course
Diagonals on tables transposed to columns
Hi Anthony,
Great course. Great trainer! Many thanks for helping with the VBA code to convert diagonals sourced from a pivot table to columns. Be grateful if you could post the code and I'll see if I can get it working when I'm at work next week. Cheers Ben.
RE: Diagonals on tables transposed to columns
Hi Ben, thanks for the compliment! Here's the transposition code - you'll need to adjust the worksheet names if they are not "Sheet1" and "Sheet2" for source and destination data. One other thing, if you run this directly on a Pivot table you may need to disable the GetPivotData functionality. Let me know if you need help with this.
Here's the code:
*****
Option Explicit
Sub transpose_me()
Dim intTargetRowCount As Integer
Dim inttargetcolumncount As Integer
Dim diagonal As Integer
Dim shuntdown As Integer
Dim across As Integer
'set initial coordinates for first straightened diagonal
intTargetRowCount = 1
inttargetcolumncount = 1
'determine the number of diagonals
For diagonal = 1 To Sheets("sheet1").Range("a1").CurrentRegion.Columns.Count
shuntdown = 1
For across = diagonal To Sheets("Sheet1").Range("a1").CurrentRegion.Columns.Count
Sheets("sheet2").Cells(intTargetRowCount, inttargetcolumncount) = Cells(shuntdown, across + 1)
intTargetRowCount = intTargetRowCount + 1 'move down a row on destination sheet
shuntdown = shuntdown + 1 'increment the row number on source sheet
Next across 'move to next column
'reset coordinates for new straightened diagonal
inttargetcolumncount = inttargetcolumncount + 1
intTargetRowCount = 1
'move onto the next diagonal
Next diagonal
End Sub
*****
Hope this helps,
Anthony
Sat 9 Jul 2011: Automatically marked as resolved.
Training information:
Welcome. Please choose your application (eg. Excel) and then post your question. Our Microsoft Qualified trainers will then respond within 24 hours (working days). Frequently Asked Questions
Any suggestions, questions or comments? Please post in the Improve the forum thread. |
Excel tip:Change the default location for opening and saving spreadsheetsIf you are always opening spreadsheets from and/or saving documents to a specific location that is not My Documents, save time by setting this folder as the default for opening files from and saving files to. |