Transposing is taking a rectangular block of data and rotating it so that columns become rows and vice versa. : Cell « Excel « VBA / Excel / Access / Word

Home
VBA / Excel / Access / Word
1.Access
2.Application
3.Data Type
4.Data Type Functions
5.Date Functions
6.Excel
7.File Path
8.Forms
9.Language Basics
10.Math Functions
11.Outlook
12.PowerPoint
13.String Functions
14.Windows API
15.Word
16.XML
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
VBA / Excel / Access / Word » Excel » Cell 
Transposing is taking a rectangular block of data and rotating it so that columns become rows and vice versa.
 
Public Sub Transpose()
    Dim As Integer
    Dim As Integer
    Dim transArray() As Variant
    Dim numRows As Integer
    Dim numColumns As Integer
    Dim colIndex As Integer
    Dim rowIndex As Integer
    Dim inputRange As Range

    Set inputRange = ActiveWindow.Selection
    colIndex = inputRange.Column
    rowIndex = inputRange.Row
    numRows = inputRange.Rows.Count
    numColumns = inputRange.Columns.Count
    ReDim transArray(numRows - 1, numColumns - 1)
    For I = colIndex To numColumns + colIndex - 1
        For J = rowIndex To numRows + rowIndex - 1
            transArray(J - rowIndex, I - colIndex= Cells(J, I).Value
        Next J
    Next I
    inputRange.ClearContents
    For I = colIndex To numRows + colIndex - 1
        For J = rowIndex To numColumns + rowIndex - 1
            Cells(J, I).Value = transArray(I - colIndex, J - rowIndex)
        Next J
    Next I
    Cells(rowIndex, colIndex).Select
End Sub

 
Related examples in the same category
1.Is a cell empty
2.Get the last cell
3.Magic Squares
4.Nest If statement in Do Loop While with comparison operators
5.Nest If statement in Do Loop Until for cells
6.Is active cell empty
7.Uses nested For/Next loops to count the total number of cells used in all open worksheets:
8.Selects cell G4
9.A better way to write to a range:Filling a range
10.Use arrays to fill ranges faster
11.Moving the pointer to the cell containing the greatest value
java2s.com  |  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.