diagonals tables transposed colu

Forum 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

resolvedResolved · 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 courses

 

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
What does 'Resolved' mean?

Any suggestions, questions or comments? Please post in the Improve the forum thread.


 

Excel tip:

Change the default location for opening and saving spreadsheets

If 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.

Here's how:
1. Go to Tools - Options.

2. Select the General tab.

3. Enter the pathname of the folder you wish to make the default in the Default File Location box (hint: it will be easier to use Windows Explorer to navigate to this folder, then copy and paste the pathname from the address bar at the top of the Windows Explorer screen).

4. Click OK.

You have now changed the default folder for opening and saving spreadsheets.

View all Excel hints and tips


Server loaded in 0.07 secs.