Collate data into one worksheet

djsmarties

Board Regular
Joined
Sep 10, 2002
Messages
95
Hi,

I am trying to copy data from several temporary worksheets into one main worksheet. I found the code below to copy the data from "Temp" to "Temp2" and it works fine with one worksheet.

Dim lRow1 As Long, lRow2 As Long, lCount As Long
Dim wsFr As Worksheet, wsTo As Worksheet

Set wsFr = Sheets("Temp")
Set wsTo = Sheets("Temp2")

With WorksheetFunction
lRow1 = .Max(wsFr.Cells(Rows.Count, "A").End(xlUp).Row)
lCount = lRow1
lRow2 = .Max(wsTo.Cells(Rows.Count, "A").End(xlUp).Row)
End With
wsTo.Range("A" & lRow2, "BW" & lRow2 + lCount).Value = wsFr.Range("A1:BW" & lRow1).Value


The problem is the following.
I am using a userform with tick boxes to let the user select which files he/she wants to import. Each tickbox activates the macro to import a file from the desktop, copy it into the "Temp" worksheet, then copy it to the "Temp2" worksheet. On its own the macro works fine, however, if I select more than one tickbox (i.e. import 2 files), the first file gets imported and copied to "Temp2" fine, the second however only gets as far as copying to "Temp" (i.e does not get added to the data already in Temp2"). I thought the code above is supposed to copy data to the first empty row in Temp2?

Thanks for your advise, I really have no idea where I am going wrong..
 

Excel Facts

Why are there 1,048,576 rows in Excel?
The Excel team increased the size of the grid in 2007. There are 2^20 rows and 2^14 columns for a total of 17 billion cells.

djsmarties

Board Regular
Joined
Sep 10, 2002
Messages
95
Does someone have any ideas on this...I am kind of stuck with my project without a solution to the above problem..

Thanks a lot.
 

Forum statistics

Threads
1,176,629
Messages
5,904,123
Members
435,074
Latest member
McKay_S

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