LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Junior Member
 
Posts: 1
Default Transpose data into a single cloumn

Hi everyone

I have just started learning VBA and a friend designed the following macro.
The macro takes information from Cell A2 to F2 and creates a new record in a single column. That is the is transposed from horizontal across columns to a single column, with line break at each record.

This macro works very well.

I would like to learn more about VBA and apply this knowledge using this macro.


I would appreciate if a member could add some comments against each line so I can understand what the code is doing.

For example is the following selecting the first record down to the last record in the worksheet.

Range("A2").Select ' start point

Selection.End(xlDown).Select ' bottom record
lastRow = ActiveCell.Row


Thanks Davidshe
Sub UpdateData()

' assuming columns don't go beyond the Z column

Dim lastColumn As String, currentRow As String, destinationArray As String 'string = text
Dim i As Integer, lastRow, numOfColumns As Integer, destinationStart As Integer ' Interger = number

Application.ScreenUpdating = False ' opening

Range("A2").Select ' start point

Selection.End(xlDown).Select ' bottom record
lastRow = ActiveCell.Row

Selection.End(xlToRight).Select
numOfColumns = ActiveCell.Column + 1
lastColumn = (Chr(numOfColumns + 64)) ' maximum columns could be 1 to max etc

' should add in a line here to clear old tranposed data

destinationStart = lastRow

For i = 2 To lastRow
currentRow = "A" & i & ":" & lastColumn & i
destinationArray = "A" & destinationStart + 5 & ":A" & destinationStart + 3 + numOfColumns
Range(destinationArray).FormulaArray = "=transpose(" & currentRow & ")"
destinationStart = destinationStart + numOfColumns
Next i

Application.ScreenUpdating = True 'closing

End Sub
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Average selected data in a cloumn Butch[_2_] Excel Discussion (Misc queries) 1 October 8th 09 05:26 PM
Missing Cloumn data when importing external data Findus Excel Discussion (Misc queries) 0 December 16th 08 11:22 AM
Transpose data from many horizontal rows into a single column Tinkmodbod Excel Discussion (Misc queries) 3 July 10th 07 04:31 PM
copying data from matching cloumn kuansheng Excel Worksheet Functions 8 March 21st 06 01:52 AM
Transpose Rows to a single a Column one below other Rashid Khan Excel Programming 11 July 7th 04 09:45 AM


All times are GMT +1. The time now is 09:23 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"