diagonals tables transposed colu
The UK's Number 1 for Microsoft Office Training Add this page to your favourites/bookmarksBookmark page
 
View printable version of pagePrintable version
Plus One Google
Customer: Sign in
Delegate: Sign in
Trainer: Log in

Forum home » Delegate support and help forum » Microsoft Excel VBA Training and help » Diagonals on tables transposed to columns

Diagonals on tables transposed to columns

resolvedResolved · Low Priority · Version 2007

replyReply Sat 2 Jul 2011, 13:22Delegate Ben said...

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.

For upcoming training course dates see: Pricing & availability

replyReply Sat 2 Jul 2011, 21:50Trainer Anthony said...

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.

 

Please browse our web site to find out more about
excel vba course london and other Microsoft training courses.

Excel tip:

Hiding a worksheet in Excel

Want to circulate an Excel workbook file but keep certain worksheets hidden from your colleagues' view?

You can do so by bringing up the sheet you wish to hide on your screen; then going to Format - Sheet - Hide.

It will not be immediately obvious that a sheet is hidden from view unless perhaps the sheet are still labelled Sheet 1, Sheet 2 etc.

To display the sheet again, you can go to Format - Sheet - Unhide on any of the other sheets in the workbook. A dialogue box will appear, allowing you to select the hidden sheet/s. Click OK to make the sheet/s reappear again.

View all Excel hints and tips


Microsoft Certified Partner Accredited Training Provider: Institute of IT Training Institute of Leadership and Management - Certified Courses Security Seal verified by visa, mastercard securecard