Help Oh Great Ones!

SAllen

New Member
Joined
Aug 28, 2002
Messages
11
when I run the macro below the new workbook is created but no data shows?
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 seems to work OK (no need to apologise, it just gets a bit confusing if your question gets split across a number of separate threads, as people aren't sure where you're up to :) ). No need to set references to an activeworkbook or worksheet with Workbooks.Add, the first worksheet of the new workbook will be active anyway: -

Code:
Sub CopyData()

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

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

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

End Sub
 
Upvote 0

Excel Facts

Pivot Table Drill Down
Double-click any number in a pivot table to create a new report showing all detail rows that make up that number

Forum statistics

Threads
1,214,980
Messages
6,122,563
Members
449,088
Latest member
Motoracer88

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
Back
Top