LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 3,365
Default macro from columns to rows but adding every time a new line

This solution does the transposition manually, and doesn't require the two
source columns to be adjacent. Only requirement is that things are defined
so that there will always be a blank row above whatever row you decide the
first horizontal copy of the first column ends up in.

Sub RecordColumnEntries()
'these identify the columns
'to be copied
Const firstColumnID = "A"
Const firstColumnRow = 1
Const secondColumnID = "B"

'this identifies where to
'put the first row of the 1st copy
'note that there must be at least
'one empty row between the last
'entry in the columns and this row.
Const firstCopyColumn = "G"
Const firstCopyToRow = 8

'variables used in the moving
Dim nextCopyToRow As Long
Dim sourceBase As Range
Dim destBase As Range
Dim copyOffset As Long

nextCopyToRow = Range(firstCopyColumn & _
Rows.Count).End(xlUp).Row
If nextCopyToRow < firstCopyToRow Then
nextCopyToRow = firstCopyToRow
Else
nextCopyToRow = nextCopyToRow + 1
End If

Set sourceBase = Range(firstColumnID & _
firstColumnRow)
Set destBase = Range(firstCopyColumn & _
nextCopyToRow)
Do While Not _
IsEmpty(sourceBase.Offset(copyOffset, 0))
destBase.Offset(0, copyOffset) = _
sourceBase.Offset(copyOffset, 0)
copyOffset = copyOffset + 1
Loop

Set destBase = destBase.Offset(1, 0)
Set sourceBase = Range(secondColumnID & _
firstColumnRow)
copyOffset = 0
Do While Not _
IsEmpty(sourceBase.Offset(copyOffset, 0))
destBase.Offset(0, copyOffset) = _
sourceBase.Offset(copyOffset, 0)
copyOffset = copyOffset + 1
Loop
Set sourceBase = Nothing
Set destBase = Nothing
End Sub


" wrote:

Hello

I would like to have a code that transforms 2 or more columns in rows.
The special thing here is that if I change the values in the same
columns and run again the macro the new values should apear under the
old lines.

Example:

Column1 - Column2
A --------------- X
B --------------- Y
C --------------- Z

When I run the macro I want that it apears in another place in the
same document same sheet like this:

Line 1 - A B C
Line 2 - X Y Z

If I run again the macro by not changing the data in the columns the
list should update by adding the same thing under the fist 2 lines -
like this:

Line 1 - A B C
Line 2 - X Y Z
Line 3 - A B C
Line 4 - X Y Z

If I change the data in the same Columns like this....

Column1 - Column2
D --------------- G
E --------------- H
F --------------- I

.....and then run again the macro the list should update again by
adding the 2 lines like this:

Line 1 - A B C
Line 2 - X Y Z
Line 3 - A B C
Line 4 - X Y Z
Line 5 - D E F
Line 6 - G H I


I already have some kind of codes that do something similar but I need
them combined somehow:

Fist code:

Sub RoundedRectangle1_Click()
a = 27

Do While Cells(a, 3).Value < ""
a = a + 1
Loop

Cells(a, 3).Value = Range("C26").Value
End Sub


Second code:

Sub Macro6()
Range("A1:B37").Select
Selection.Copy
Range("G8").Select
Selection.PasteSpecial Paste:=xlPasteAll, Operation:=xlNone,
SkipBlanks:= _
False, Transpose:=True
Range("G8").Select
End Sub

I would really appreciate your help

Thanks in advance

 
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
adding more columns/rows Jo Davis Excel Discussion (Misc queries) 4 September 24th 08 07:57 PM
adding time in columns BAKERSMAN Excel Discussion (Misc queries) 2 June 3rd 08 05:53 PM
Adding up columns for speciic rows confused Excel Worksheet Functions 1 March 3rd 08 04:16 PM
time columns not adding correctly student New Users to Excel 2 February 9th 08 10:48 PM
Adding series, this time with a 2 axes line chart Barb Charts and Charting in Excel 1 December 9th 05 08:48 AM


All times are GMT +1. The time now is 02:32 PM.

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"