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..
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..