Copying Cells

SAllen

New Member
Joined
Aug 28, 2002
Messages
11
I am trying to copy the same specific cells from each sheet in a workbook and copy that to a new workbook. The macro debuger gives me a run-time error '1004' Application-defined or object-defined error stops at the range line. I'm running this from a xls spreadsheet named Cdabakup.xls, could this be a problem? Can anyone help?

Sub Copy()


Dim ws As Worksheet
Dim CellstoCopy() As Variant
Dim x As Integer

For Each ws In ThisWorkbook.Worksheets
ReDim Preserve CellstoCopy(x + 1)
CellstoCopy(x) = ws.[g13]
CellstoCopy(x + 1) = ws.[g32]
x = x + 2
Next ws

Workbooks.Add
Range(Cells(1, 1), Cells(1, x)) = CellstoCopy


End Sub
This message was edited by SAllen on 2002-08-29 18:32
 

Excel Facts

Using Function Arguments with nested formulas
If writing INDEX in Func. Arguments, type MATCH(. Use the mouse to click inside MATCH in the formula bar. Dialog switches to MATCH.

larai

New Member
Joined
Aug 28, 2002
Messages
20
Hmnnn...what do you mean by stops?

I pasted your code into a new book and ran it and it works fine...?

On the new workbook that gets created, I get 4 columns of data on row 1 (I had 2 spreadsheets with data in cells G13 & G32.
 

Forum statistics

Threads
1,147,688
Messages
5,742,626
Members
423,744
Latest member
bkirtland

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Top