Thread: Copy/Paste?
View Single Post
  #4   Report Post  
Posted to microsoft.public.excel.programming
ryguy7272 ryguy7272 is offline
external usenet poster
 
Posts: 2,836
Default Copy/Paste?

Hi, just thought the poster may want to see a small modification required to
Per's code:

Sub CopyPaste()
Dim shA As Worksheet
Dim shB As Worksheet
Dim LastRow As Long
Dim r As Long
Dim Item As String

Set shA = Worksheets("Sheet1") 'Change to suit
Set shB = Worksheets("Sheet2") 'Change to suit

LastRow = shA.Range("A1").End(xlDown).Row

For rw = 1 To LastRow
Item = shA.Cells(rw, 1)
r = r + 1
shB.Cells(r, 2) = shA.Cells(rw, 2)
r = r + 1
shB.Cells(r, 2) = shA.Cells(rw, 2) & " " & shA.Cells(rw, 3)
r = r + 1
shB.Cells(r, 2) = shA.Cells(rw, 2) & " " & shA.Cells(rw, 4)
Next

End Sub

HTH,
Ryan---

--
Ryan---
If this information was helpful, please indicate this by clicking ''Yes''.


"Per Jessen" wrote:

Hi
Try this.

Sub CopyPaste()
Dim shA As Worksheet
Dim shB As Worksheet
Dim LastRow As Long
Dim r As Long
Dim Item As String

Set shA = Worksheets("Sheet1") 'Change to suit
Set shB = Worksheets("Sheet2") 'Change to suit

LastRow = shA.Range("A1").End(xlDown).Row

For rw = 1 To LastRow
Item = shA.Cells(rw, 1)
r = r + 1
shB.Range("A" & r & ":A" & r + 1) = Item
shB.Cells(r, 2) = shA.Cells(rw, 2)
r = r + 1
shB.Cells(r, 2) = shA.Cells(rw, 3)
Next
End Sub

Regards,
Per

On 5 Aug., 00:00, Mike G - DC
wrote:
Folks - I'm looking for some code to copy data from worksheet A into
Worksheet B like the following example. This code will fire as part of
another macro. Any help is much appreciated.
Thanks, Mike

Worksheet A
A B C
1 item1 10 20
2 item2 12 19
3 item3 13 89

Worksheet B
A B
1 item1 10
2 item1 20
3 item2 12
4 item2 19
5 item3 13
6 item3 89