0

Please can you assist me with what appears to be a simple problem? Note, this question is close to being a last resort since I have tried all the usual sites to find an answer but frustratingly, without success.

I am using Excel vba. I want to copy some values from a worksheet into another worksheet in the same workbook.

The line of code I have produced is as follows:

Range(Cells(1, 4), Cells(1, 6)) = Worksheets("Summary Data").Range(Cells(1, 4), Cells(1, 6))

This line of code produces a 'Run-time error 1004'.

If I run the following line of code it runs fine:

Range(Cells(1, 4), Cells(1, 6)) = Worksheets("Summary Data").Cells(1, 4)

However, I want to copy the range on Worksheet "Summary Data" into another worksheet.

Please could someone assist me in the management of my blood pressure by offering an explanation for the error above and / or a solution?

Community
  • 1
  • 1
  • See if this helps :) http://stackoverflow.com/questions/8047943/excel-vba-getting-range-from-an-inactive-sheet Let me know if you still want an explanation. – Siddharth Rout Apr 25 '12 at 19:18

2 Answers2

0

I will tell simple solution follow that. Start recording a macro and copy which cells you want to copy to another sheet and paste there and stop recording macro. Then go to visual basic editor and see the macro code.

0

Old question, but...

Perhaps you need to qualify your statement:

Range(Cells(1, 4), Cells(1, 6)).Value = _
  Worksheets("Summary Data").Range(Cells(1, 4), Cells(1, 6)).value

or qualify your ranges more fully:

Dim ws1 As Worksheet, ws2 As Worksheet
Set ws1 = ActiveSheet
Set ws2 = Worksheets("Summary Data")

ws1.Range(ws1.Cells(1,4), ws1.Cells(1,6)).Value = _
  ws2.Range(ws2.Cells(1,4), ws2.Cells(1,6)).Value
Jon Peltier
  • 5,895
  • 1
  • 27
  • 27