Simple question

J

jcrmeyer

I have a worksheet "Orderform" containing a range B8:B12 and a variable
number of rows starting A17:D17, A18:D18, etc.

I need to copy this data over to another sheet "Orders" in a different
workbook such that the range B8:B12 is transposed and pasted at the
beginning of each row and the end of each row is a straight copy from
"Orderform". So it ends up like this:

B8 B9 B10 B11 B12 A17 B17 C17 D17
B8 B9 B10 B11 B12 A18 B18 C18 D18
B8 B9 B10 B11 B12 A19 B19 C19 D19
etc

I've written a macro to do this (see below) but it seems a bit messy.
I'm new to this and sure there's a more efficient way of doing it. In
particular I'm thinking there must be a way to combine the vertical and
horizontal ranges and pasting in one go rather than doing it in two
chunks as I have...any advice much appreciated


Workbooks("order.xls").Sheets("Orderform").Activate
Dim rw As Long
rw = 17

Do Until ActiveSheet.Cells(rw, 1) = ""

Range(Cells(8, 2), Cells(12, 2)).Select
Application.CutCopyMode = False
Selection.Copy

Workbooks("master.xls").Sheets("Orders").Activate
Range("A1").End(xlDown).Offset(1, 0).Select
Selection.PasteSpecial Paste:=xlPasteValuesAndNumberFormats,
Operation:= _
xlNone, SkipBlanks:=False, Transpose:=True

Workbooks("order.xls").Sheets("Orderform").Activate
Range(Cells(rw, 1), Cells(rw, 4)).Select
Application.CutCopyMode = False
Selection.Copy

Workbooks("master.xls").Sheets("Orders").Activate
Range("F1").End(xlDown).Offset(1, 0).Select
Selection.PasteSpecial Paste:=xlPasteValuesAndNumberFormats,
Operation:= _
xlNone, SkipBlanks:=False, Transpose:=False

Workbooks("order.xls").Sheets("Orderform").Activate

rw = rw + 1

Loop
 
J

Jim Rech

Do Until ActiveSheet.Cells(rw, 1) = ""

Fyi, Cells always refers to the active sheet

You do not have to select a range to copy it or paste to it.

You do not have to clear the clipboard before using it.

So...

Range(Cells(8, 2), Cells(12, 2)).Copy
Workbooks("master.xls").Sheets("Orders").Range("A1").End(xlDown).Offset(1).PasteSpecial
Paste:=xlPasteValuesAndNumberFormats, Operation:= xlNone, SkipBlanks:=False,
Transpose:=True


--
Jim
|I have a worksheet "Orderform" containing a range B8:B12 and a variable
| number of rows starting A17:D17, A18:D18, etc.
|
| I need to copy this data over to another sheet "Orders" in a different
| workbook such that the range B8:B12 is transposed and pasted at the
| beginning of each row and the end of each row is a straight copy from
| "Orderform". So it ends up like this:
|
| B8 B9 B10 B11 B12 A17 B17 C17 D17
| B8 B9 B10 B11 B12 A18 B18 C18 D18
| B8 B9 B10 B11 B12 A19 B19 C19 D19
| etc
|
| I've written a macro to do this (see below) but it seems a bit messy.
| I'm new to this and sure there's a more efficient way of doing it. In
| particular I'm thinking there must be a way to combine the vertical and
| horizontal ranges and pasting in one go rather than doing it in two
| chunks as I have...any advice much appreciated
|
|
| Workbooks("order.xls").Sheets("Orderform").Activate
| Dim rw As Long
| rw = 17
|
| Do Until ActiveSheet.Cells(rw, 1) = ""
|
| Range(Cells(8, 2), Cells(12, 2)).Select
| Application.CutCopyMode = False
| Selection.Copy
|
| Workbooks("master.xls").Sheets("Orders").Activate
| Range("A1").End(xlDown).Offset(1, 0).Select
| Selection.PasteSpecial Paste:=xlPasteValuesAndNumberFormats,
| Operation:= _
| xlNone, SkipBlanks:=False, Transpose:=True
|
| Workbooks("order.xls").Sheets("Orderform").Activate
| Range(Cells(rw, 1), Cells(rw, 4)).Select
| Application.CutCopyMode = False
| Selection.Copy
|
| Workbooks("master.xls").Sheets("Orders").Activate
| Range("F1").End(xlDown).Offset(1, 0).Select
| Selection.PasteSpecial Paste:=xlPasteValuesAndNumberFormats,
| Operation:= _
| xlNone, SkipBlanks:=False, Transpose:=False
|
| Workbooks("order.xls").Sheets("Orderform").Activate
|
| rw = rw + 1
|
| Loop
|
 

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