Link to home
Start Free TrialLog in
Avatar of Avinash Singh
Avinash Singh

asked on

Modification of the vba code, file is bigger and the code is very slow

I had this question after viewing combine sheet1,sheet2,sheet3,sheet4,sheet5 into 1sheet.
This is my actual file but it is bigger than this i have deleted 75% of data bcoz i can't upload the file  above 50mb  here
the current code is unable to handle this much of data and it is very slow so plz look into it and do needful
plz see the actual file in the attachment
Actual-File.xlsb
Avatar of Roy Cox
Roy Cox
Flag of United Kingdom of Great Britain and Northern Ireland image

When I tried your original code I received an "Out of Memory" error.

This code does not error, but the amount of data to copy doesmeabs a slow process.

Sub STEP12()
    Dim oWs As Worksheet
    Dim lRw As Long
    On Error GoTo exit_proc
    Application.ScreenUpdating = False
    With Sheets("Combined")
        .Cells.Clear
        For Each oWs In ThisWorkbook.Worksheets
            If oWs.Name <> "Combined" Then
                lRw = .Cells(.Rows.Count, 1).End(xlUp).Row + 1
                If lRw = 2 Then lRw = 1
                oWs.Range("A1").CurrentRegion.Copy Sheets("Combined").Cells(lRw, 1)
            End If
        Next oWs
    End With
exit_proc:
    Application.ScreenUpdating = True
End Sub

Open in new window

Avatar of Avinash Singh
Avinash Singh

ASKER

Code is slow
Plz look into it
With that amount of data you cannot expect fast code.
Roy sir plz check the code i am not getting result from this code plz run ur code in my actual file  u will not get any result
 i want the result in sheet6 and we have to combined the data of sheet1,sheet2,sheet3,sheet4,sheet5
Obviously I checked the code, it runs fine but slow. I simply changed the name of the destination sheet to Combined
Roy sir plz look into this sample file
we have to combined all the data as shown in this sample file
Book101.xlsb
That's nothing like the file you posted previously, You combine that with formulas.

Here's the code for the previous file changed back to Sheet6, the file will not upload
Sub STEP12()
    Dim oWs As Worksheet
    Dim lRw As Long
    On Error GoTo exit_proc
    Application.ScreenUpdating = False
    With Sheets("Sheet6")
        .Cells.Clear
        For Each oWs In ThisWorkbook.Worksheets
            If oWs.Name <> "Combined" Then
                lRw = .Cells(.Rows.Count, 1).End(xlUp).Row + 1
                If lRw = 2 Then lRw = 1
                oWs.Range("A1").CurrentRegion.Copy Sheets("Sheet6").Cells(lRw, 1)
            End If
        Next oWs
    End With
exit_proc:
    Application.ScreenUpdating = True
End Sub

Open in new window

That code crashed when I tried to run it on your example file. As I said it produced an out of memory error. The code that I posted does not crash.
ASKER CERTIFIED SOLUTION
Avatar of Ejgil Hedegaard
Ejgil Hedegaard
Flag of Denmark image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thnx Ejgil Sir for giving ur precious time and great support to this post
Ejgil Sir the result from ur code is different
I am attaching my actual file  with macro plz look into it
and when i run the macro it shows out of memory error
Actual-File.xlsb
The data in last uploaded file is not the same as the previous sample file.
I tried with 50 rows with the data from the last uploaded file, and run with both codes, and the results are identical.
Please describe what is wrong.
We have to combine data of sheet1,sheet2,sheet3,sheet4,sheet5
And the result should be in sheet6
Combine means  Sheet1 A1 cell data,sheet2 A1 cell data,sheet3 A1 cell data,sheet4 A1 cell data,sheet5 A1 cell data into sheet6 A1 cell  
So this we have to do with all the data
Plz reopen  this post i dont know how to do it  and plz look into this post
That is exactly what the code does.
There are data In row 440 for Sheet 1, 2 and 3, nothing in sheet 4 and 5.
Sheet 1 and 2 from A to XFD, and sheet 3 from A to DX.
Sheet1 A440 is "1 L 1", and XFD440 is "1 L 1"
Sheet2 A440 is "1 L 1", and XFD440 is "1 G 1"
Sheet3 A440 is "1 G 1", and XFD440 is empty
Sheet6 A440 is "1 L 1,1 L 1,1 G 1", and XFD440 is "1 L 1,1 G 1"

Please describe what is wrong.
Sorry Ejgil sir ur code is perfect
Thnx Ejgil Sir for giving ur precious time and great support to this post