INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
• Talk With Other Members
• Be Notified Of Responses
• Keyword Search
Favorite Forums
• Automated Signatures
• Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

#### Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

# VBA Visual Basic for Applications (Microsoft) FAQ

 Forum Search FAQs Links MVPs

## Excel How To

How can I Transpose Data In Excel Via VBA by Chance1234
Posted: 15 Feb 06

Please Make sure you read up on arrays and ranges so you can better understand the code below.

#### CODE

Sub Transpose()
' Very quick example
' On sheet1 add into cells B2:B12, any value you like

Dim intCnt As Integer ' counter
Dim intR, intC As Integer ' Row and column counters
Dim arrC(12) As Variant ' tempoary storage array

intCnt = 1
intR = 2 ' Row 2
intC = 2 ' Column B

'Load Data into array
Do Until intCnt = 12
'Nb re the 12 above, this is quick and dirty but there are
'many ways you can come up with this figure, or you could
'use a named range, or pass a range to a array and use Ubound(range)

'load data into array
arrC(intCnt) = Sheet1.Cells(intR, intC)
'i know the size of my array here, but if i didnt
'i would use redim preserve every time i added data, to increae
'the size of the array
intCnt = intCnt + 1 'increase count
intR = intR + 1 'increase row
Loop

'Now data is loaded into array, we will move
'through it and populate from cell D2

intCnt = 1
intR = 2 ' Row 2
intC = 4 ' Column D

Do Until intCnt = 12

Sheet1.Cells(intR, intC) = arrC(intCnt)
intCnt = intCnt + 1 'increase count
intC = intC + 1 ' increase column
Loop

Back to VBA Visual Basic for Applications (Microsoft) FAQ Index
Back to VBA Visual Basic for Applications (Microsoft) Forum

Close Box

# Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

• Talk To Other Members
• Notification Of Responses To Questions
• Favorite Forums One Click Access
• Keyword Search Of All Posts, And More...

Register now while it's still free!