combining 1000 separated ranges from multiple sheets into one

Alaa mg

Active Member
Joined
May 29, 2021
Messages
378
Office Version
  1. 2019
Hello

I have about 1000 separated range in each sheet , and each range could contain at least 15 rows so the final rows are about 15000 rows .

every sheet contains name so when put the ranges under each other should create name for each range based on sheet name

the result in COMBINED sheet and will add new sheet before COMBINED sheet every time so should delete data in COMBINED sheet when copy data every time

insert.xlsm
ABCDE
1DATEDescribeDEBITCREDITBALANCE
205/01/2022NOT PAID12331233
306/01/2022NOT PAID12332466
407/01/2022PAID2000466
508/01/2022PAID4660
ALA



insert.xlsm
ABCDE
1DATEDescribeDEBITCREDITBALANCE
208/01/20220
309/01/2022NOT PAID20002000
411/01/2022NOT PAID200010003000
511/01/2022NOT PAID200050000
MAL


insert.xlsm
ABCDE
1DATEDescribeDEBITCREDITBALANCE
211/01/20220
312/01/2022NOT PAID15001500
413/01/2022NOT PAID5002000
514/01/2022PAID200010003000
615/01/2022PAID10101990
716/01/2022PAID1000990
817/01/2022PAID9900
MOUNIRR


I expect like this
insert.xlsm
ABCDE
1NAME
2ALA
3DATEDescribeDEBITCREDITBALANCE
405/01/2022NOT PAID12331233
506/01/2022NOT PAID12332466
607/01/2022PAID2000466
708/01/2022PAID4660
8
9
10NAME
11MAL
12DATEDescribeDEBITCREDITBALANCE
1308/01/20220
1409/01/2022NOT PAID20002000
1511/01/2022NOT PAID200010003000
1611/01/2022NOT PAID200050000
17
18
19NAME
20MOUNIRR
21DATEDescribeDEBITCREDITBALANCE
2211/01/20220
2312/01/2022NOT PAID15001500
2413/01/2022NOT PAID5002000
2514/01/2022PAID200010003000
2615/01/2022PAID10101990
2716/01/2022PAID1000990
2817/01/2022PAID9900
COMBINED

thanks.
 

Excel Facts

Will the fill handle fill 1, 2, 3?
Yes! Type 1 in a cell. Hold down Ctrl while you drag the fill handle.
I am not sure what you want done with this part
and will add new sheet before COMBINED sheet every time so should delete data in COMBINED sheet when copy data every time
But this should at least get you half way there...

VBA Code:
Sub getRanges()

    Dim ws As Worksheet
    Dim wsC As Worksheet: Set wsC = Worksheets("COMBINED")
    Dim lRow As Long, adr As Long
    
    Application.ScreenUpdating = False
    For Each ws In ActiveWorkbook.Worksheets
        If Not ws.Name = wsC.Name Then
            lRow = Cells(Rows.Count, 1).End(xlUp).Row + adr
            With wsC.Cells(lRow, 3)
                .Value = "NAME"
                .Interior.Color = RGB(156, 193, 227)
            End With
            wsC.Cells(lRow + 1, 3) = ws.Name
            ws.UsedRange.Copy wsC.Cells(lRow + 2, 1)
        End If
        adr = 3
    Next ws
    Application.ScreenUpdating = True

End Sub
 
Upvote 0
I am not sure what you want done with this part
to avoid repeating to copying data have already copied to the bottom ,your code does it . should not do that.
 
Upvote 0
Are you saying that the provided code satisfies your requirement as posted or do you need additional help...
 
Upvote 0
not really .
first your code need fixing as explained in post #3
second the code seems to work greatly with simple data .
third I have to test it with big data at work tomorrow to see how goes.
 
Upvote 0
Ok, can you explain what needs to be fixed. Do you want the sheets deleted after they are copied or do you want the current information on the copied sheets deleted. If you can explain exactly what you want done, we can alter the code.
 
Upvote 0
just delete data in combined sheet after they are copied
in other meaning delete data have already copied before copied data again when run the macro every time
this calls replace data.
Do you want the sheets deleted after they are copied or do you want the current information on the copied sheets deleted.
Neither
 
Upvote 0
Is this what you want. Please test on a backup copy of your data as this code will delete data which is not easily recoverable...

VBA Code:
Sub getRanges()

    Dim ws As Worksheet
    Dim wsC As Worksheet: Set wsC = Worksheets("COMBINED")
    Dim lRow As Long, adr As Long
    
    Application.ScreenUpdating = False
    With wsC
        .Cells.Clear
        .Activate
    End With
    For Each ws In ActiveWorkbook.Worksheets
        If Not ws.Name = wsC.Name Then
            lRow = Cells(Rows.Count, 1).End(xlUp).Row + adr
            With wsC.Cells(lRow, 3)
                .Value = "NAME"
                .Interior.Color = RGB(156, 193, 227)
            End With
            wsC.Cells(lRow + 1, 3) = ws.Name
            ws.UsedRange.Copy wsC.Cells(lRow + 2, 1)
        End If
        adr = 3
    Next ws
    Application.ScreenUpdating = True

End Sub
 
Upvote 1
Solution
yes this what I want it .
well , your code is really efficient and fast with simple data but I will inform you tomorrow if I need help you .;)
thank you .
 
Upvote 0
Ok, I only have the simple data that you provided. To be honest, if this code is used on a large amount of data it will slow down drastically. The reason being is that the code is going back & forth to the worksheets (copying & pasting) in the middle of the loop. That is a very inefficient method of coding and will slow the code down.
That said, without seeing your real data, it is hard to know how the code can be written to accommodate your true data.
 
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