ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Copy Cells from columns to rows (https://www.excelbanter.com/excel-programming/282639-copy-cells-columns-rows.html)

SKipC

Copy Cells from columns to rows
 
I need A1:A3 then A4:A6 then A7:A8 copied to Row ?(1,3), row ? (1,3), row ? (1,3) depending on the row heading, then delete cell color and Print sheet: Can anyone help with some generic code for me Please!!! ie.
A1
A2 2.
A3 $1.5
A4
A5
A6 $3.0
A7
A8
A9 $4.5

Family Type Pounds Pric
C A 2.5 $1.5
P B 2 $3.0
M C 4 $4.50

keepITcool

Copy Cells from columns to rows
 


Sub Test()
Dim v
v = ListToTable([a1].currentregion, 3)
[a1].currentregion.clear
[a1].Resize(UBound(v, 1), UBound(v, 2)) = v
End Sub

Function ListToTable(oriTable As Range, numFields As Integer)
Dim newTable As Variant, r As Long, c As Integer
ReDim newTable(1 To (1 + oriTable.Rows.Count \ numFields), 1 To
numFields)
For r = 1 To oriTable.Rows.Count Step numFields
For c = 1 To numFields
newTable(1 + r \ numFields, c) = oriTable(r + c - 1, 1)
Next
Next
ListToTable = newTable
End Function


keepITcool

< email : keepitcool chello nl (with @ and .)
< homepage: http://members.chello.nl/keepitcool


"?B?U2tpcGM=?=" wrote:

I need A1:A3 then A4:A6 then A7:A8 copied to Row ?(1,3), row ? (1,3),
row ? (1,3) depending on the row heading, then delete cell color and
Print sheet: Can anyone help with some generic code for me Please!!!
ie. A1 A
A2 2.5
A3 $1.50
A4 B
A5 2
A6 $3.00
A7 C
A8 4
A9 $4.50

Family Type Pounds Price
C A 2.5 $1.50
P B 2 $3.00
M C 4 $4.50



SKipC

Copy Cells from columns to rows
 
Thanks Keep: I left out that this has to happen from sheet1 into sheet2 sorry. Where would that go in the code

SkipC

keepITcool

Copy Cells from columns to rows
 

well... i did put it in a function...
try:

Sub Test2()
Dim v
v = ListToTable([sheet1!a1].currentregion, 3)
[sheet2!a1].Resize(UBound(v, 1), UBound(v, 2)) = v
End Sub



keepITcool

< email : keepitcool chello nl (with @ and .)
< homepage: http://members.chello.nl/keepitcool


"?B?U2tpcGM=?=" wrote:

Thanks Keep: I left out that this has to happen from sheet1 into
sheet2 sorry. Where would that go in the code?

SkipC



SKipC

Copy Cells from columns to rows
 
Thanks Cool: Yoou've been a great help

Skipc


All times are GMT +1. The time now is 03:37 AM.

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