copy multiple columns

M

Milax

Can somebody help me, I need to copy values from multiple columns to one
row, for example:

A1,B1,C1,D1
A2,B2,C2,D2
A3,B3,C3,D3

in

A1,B1,C1,D1,A2,B2,C2,D2,A3,B3,C3,D3.

I don't know witch object (Range or Cell) and its parameters to us.

Thanks!
 
P

Paul Morgan

Here's a code that would work for you,

Remember that you only have 256 columns though you can ony do this fo
64 rows


Code
-------------------
Sub CutPasteToRowA()
Range("A2").Select
Do Until ActiveCell = ""
ActiveCell.Range("A1:D1").Cut Destination:=Range("A1").End(xlToRight).Offset(0, 1).Range("A1")
ActiveCell.Offset(1, 0).Select
Loop
Range("A1").Select
End Sub
 
J

Joel

Cell is index with a row number and a column number like Cells(1,3) which is
row 1 and column C.

Range has multiple for mats. the simple one is

Range("A3") where A3 is a character string. Range can also be made of cells
such as

Range(Cells(1,3),Cells(2,6))

I usually prefer to use a range with an offset such as

Range("A3:D3").offset(rowoffset:=2,columnoffset:=3)

this format is nice because you can put it in a for loop and ichange the
rows or columns

for i = 1 to 10

Range("A3:D3").offset(rowoffset:=i,columnoffset:=3)

Next i


Example 1
MyColoffset = 0
For RowCount = 1 To 3


Range("A1:D4").Offset(rowoffset:=RowCount - 1, columnoffset:=0).Copy _
Destination:=Range("A10"). _
Offset(rowoffset:=0, columnoffset:=4 * (RowCount - 1))


Next RowCount
newrange
next rowcount

Example 2

Set oldrange = Range("A1:D4")
Set newrange = Range("A10")
MyColoffset = 0
For RowCount = 1 To 3

oldrange.Offset(rowoffset:=RowCount - 1, columnoffset:=0).Copy _
Destination:=newrange. _
Offset(rowoffset:=0, columnoffset:=4 * (RowCount - 1))

Next RowCount
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top