VBA-Copy/Paste Issue Excel 2013

molinamike

New Member
Joined
May 9, 2016
Messages
10
Hello Members,

I have a file that is imported to my C:Drive from a company system; however, I am only able to import using a xls extension. The imported file exceeds the maximum rows for xls; therefore, it creates additionally data tabs. I need the file to be in xlsx format all in one sheet. Is there any code that will copy all data from each tab from a closed xls file and then open a new xlsx file and paste all of the data into one worksheet? I have to do this with 17 files so I am trying to automate this process. I have searched the board but have not found a solution that would fit my scenario. Thanks for any assistance the board can provide.:)

~Thanks
Mike
 

Excel Facts

Format cells as currency
Select range and press Ctrl+Shift+4 to format cells as currency. (Shift 4 is the $ sign).
How about
Code:
Sub AddData()
' molinamike

    Dim NewSht As Worksheet
    Dim OrigWbk As Workbook
    Dim Ws As Worksheet
    
Application.ScreenUpdating = False

    Workbooks.Add (1)
    Set NewSht = ActiveSheet
    Set OrigWbk = Workbooks.Open("[COLOR=#ff0000]C:\Users\Fluff\Documents\Excel files\ZZ2.xls[/COLOR]")
    
    For Each Ws In OrigWbk.Sheets
        Ws.Range("A1").CurrentRegion.Copy NewSht.Range("A" & Rows.Count).End(xlUp).Offset(1)
    Next Ws
    OrigWbk.Close False
    NewSht.Rows(1).Delete
    
End Sub
Change the part in red to match your path/filename
 
Upvote 0
Thank you for the response. I attempted the code you provided; however, I received a debug error stating "We can't paste because the Copy Area and Paste Area aren't the same size"


How about
Code:
Sub AddData()
' molinamike

    Dim NewSht As Worksheet
    Dim OrigWbk As Workbook
    Dim Ws As Worksheet
    
Application.ScreenUpdating = False

    Workbooks.Add (1)
    Set NewSht = ActiveSheet
    Set OrigWbk = Workbooks.Open("[COLOR=#ff0000]C:\Users\Fluff\Documents\Excel files\ZZ2.xls[/COLOR]")
    
    For Each Ws In OrigWbk.Sheets
        Ws.Range("A1").CurrentRegion.Copy NewSht.Range("A" & Rows.Count).End(xlUp).Offset(1)
    Next Ws
    OrigWbk.Close False
    NewSht.Rows(1).Delete
    
End Sub
Change the part in red to match your path/filename
 
Upvote 0
Any idea approx how many rows of data you have in total?
 
Upvote 0
This might help
Code:
Sub AddData()
' molinamike

    Dim NewSht As Worksheet
    Dim OrigWbk As Workbook
    Dim Ws As Worksheet
    
Application.ScreenUpdating = False

    Workbooks.Add (1)
    Set NewSht = ActiveSheet
    Set OrigWbk = Workbooks.Open("C:\Users\Fluff\Documents\Excel files\ZZ2.xls")
    NewSht.Activate
    For Each Ws In OrigWbk.Sheets
        Ws.Range("A1").CurrentRegion.Copy NewSht.Range("A" & Rows.Count).End(xlUp).Offset(1)
    Next Ws
    OrigWbk.Close False
    NewSht.Rows(1).Delete
    
End Sub
The only way I could replicate the error message, is if there were over 1,048,576 rows, but that is obviously not the case.
I'm off down the pub now, so will have another look at this tomorrow.
 
Upvote 0
If you create a new workbook (Ie hit Ctrl+N) Does it open as Book1 - Excel or Book1 [Compatability Mode] - Excel
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

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