ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Adding new columns from one sheet to another (https://www.excelbanter.com/excel-programming/332885-adding-new-columns-one-sheet-another.html)

hughvision

Adding new columns from one sheet to another
 

Hi all,

I am trying to code a macro that uses a for each loop, for each cell in
say Row B going down, B2:B20 create a new column for each cell on
another sheet, with the same header... So basically taking everything
from a vertical set of rows and populating another sheet with all
columns (horizontal) instead...

If anyone has any ideas, please right back.

Thanks.

Hugh.


--
hughvision
------------------------------------------------------------------------
hughvision's Profile: http://www.excelforum.com/member.php...o&userid=24660
View this thread: http://www.excelforum.com/showthread...hreadid=382389


R.VENKATARAMAN

Adding new columns from one sheet to another
 
did you try to <transpose

highlight B2 to B20
edit copy
open anoher sheet and select a cell
edit pastespecial -transpose

is that not what you want.
==================
hughvision wrote
in message ...

Hi all,

I am trying to code a macro that uses a for each loop, for each cell in
say Row B going down, B2:B20 create a new column for each cell on
another sheet, with the same header... So basically taking everything
from a vertical set of rows and populating another sheet with all
columns (horizontal) instead...

If anyone has any ideas, please right back.

Thanks.

Hugh.


--
hughvision
------------------------------------------------------------------------
hughvision's Profile:

http://www.excelforum.com/member.php...o&userid=24660
View this thread: http://www.excelforum.com/showthread...hreadid=382389




FGM

Adding new columns from one sheet to another
 
Here is part of a macro I use to get specified cells and transpose them to
another sheet.


'Get Records This loops through and picks up each group of CEL records and
'transposes it on the main wksht

Sheets("raw").Select
Rcount = Range("B25").Value 'Gets the number of CEL records
x = 1 'set starting loop count
R1 = 5 'set starting NewRange first position
R2 = 16 'set starting NewRange second position
R3 = 5 'set SendRange position
NewRange = "T5:T16" 'for first loop
SendRange = "E5" 'for first loop
dbRangeGet = "U5" ' for first loop Meas dBA data
dbRangeSend = "R5" 'for first loop Meas dBA data
Do Until x Rcount 'until it loops the number of record count
'this gets the data that needs to be transposed
Sheets("raw").Select
Range(NewRange).Select
Selection.Copy
Sheets("main").Select
Range(SendRange).Select
Selection.PasteSpecial Paste:=xlAll, Operation:=xlNone,
SkipBlanks:=False _
, Transpose:=True
'this gets the single cell that needs to be copied Meas dBA
Sheets("raw").Select
Range(dbRangeGet).Select
Selection.Copy
Sheets("main").Select
Range(dbRangeSend).Select
ActiveSheet.Paste
'The following increments the variables for the next group of records
R1 = R1 + 15 'increment 15 for the next record
R2 = R2 + 15 'increment 15 for the next record
R3 = R3 + 1 'increment 1 for the next record
NewRange = "T" & R1 & ":" & "T" & R2 ' appends the needed info for
the NewRange
SendRange = "E" & R3 'appends the needed info for the SendRange
dbRangeGet = "U" & R1 'appends the needed info for the dbRangeGet
dbRangeSend = "R" & R3 'appends the need info for the dbRangeSend
the Meas dBA
x = x + 1 'increments the count for the loop
Loop



"hughvision" wrote:


Hi all,

I am trying to code a macro that uses a for each loop, for each cell in
say Row B going down, B2:B20 create a new column for each cell on
another sheet, with the same header... So basically taking everything
from a vertical set of rows and populating another sheet with all
columns (horizontal) instead...

If anyone has any ideas, please right back.

Thanks.

Hugh.


--
hughvision
------------------------------------------------------------------------
hughvision's Profile: http://www.excelforum.com/member.php...o&userid=24660
View this thread: http://www.excelforum.com/showthread...hreadid=382389




All times are GMT +1. The time now is 12:37 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com