VBA copying from large spreadsheets

Heats

New Member
Joined
Jul 25, 2010
Messages
15
Hi people,

Hoping someone can point me in the right direction. I have some code that opened a second spreadsheet copied a range, closed the spreadsheet and pasted it into original sheet that worked for test files. However I am now trying to use it on the actual larger files and it is coming up with warnings on information on clipboard etc. I know you can disable this but have been trying to do it the following alternate way;

Code:
Public wbMain As Workbook
Public k As Integer
Sub first()
Dim pastelocation As Range

Set wbMain = ActiveWorkbook

k = Range("A" & Rows.Count).End(xlUp).Row
pastelocation = Range("A" & k + 1)

Call second
End Sub


Sub second()

Dim rSrc As Range
Dim rDst As Range
Dim wbCopyFrom As Workbook

Set wbCopyFrom = ActiveWorkbook

Set rSrc = wbCopyFrom.Sheets("Data To Copy").Range("A2:R2", Selection.End(xlDown))
Set rDst = wbMain.Sheets("Final Data").Cells("pastelocation").Resize(rSrc.Rows.Count, rSrc.Columns.Count)
rDst = rSrc.Value

End Sub

Above is the relative pieces of code and it looks like my issue is mainly around the pastelocation variable.

The sub is split as I'm looping through many excel files bringing back information from each.

Any help will be greatly appreciated.
 
Last edited:

Excel Facts

Can Excel fill bagel flavors?
You can teach Excel a new custom list. Type the list in cells, File, Options, Advanced, Edit Custom Lists, Import, OK
Hi,

I have not tried this but I think you will need to pass the Range called pastelocation in to the second sub. Otherwise it will just think it is a character string.

Try this:

Code:
Public wbMain As Workbook
Public k As Integer
Sub first()
Dim pastelocation As Range

Set wbMain = ActiveWorkbook

k = Range("A" & Rows.Count).End(xlUp).Row
pastelocation = Range("A" & k + 1)

Call second(pastelocation)
End Sub


Sub second(pastelocation As Range)

Dim rSrc As Range
Dim rDst As Range
Dim wbCopyFrom As Workbook

Set wbCopyFrom = ActiveWorkbook

Set rSrc = wbCopyFrom.Sheets("Data To Copy").Range("A2:R2", Selection.End(xlDown))
Set rDst = wbMain.Sheets("Final Data").Range(pastelocation).Resize(rSrc.Rows.Count, rSrc.Columns.Count)
rDst = rSrc.Value

End Sub
</pre>
 
Upvote 0

Forum statistics

Threads
1,215,059
Messages
6,122,917
Members
449,093
Latest member
dbomb1414

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