Copy and paste dynamic ranges from mulitple sheets to summary sheet

waqasbutt

New Member
Joined
Apr 7, 2015
Messages
22
Hi All,

I am new to VBA and I am struggling with a scenario. I have a sheet "Rawdata" and I using advance filter to extract unique record based on certain criteria into five different sheets.
In Summary sheet (attached image, how I want to display), I want to report all five tabs data into five tables in summary sheet. Since data is dynamic, so I am facing challenge to adjust rows for each table in summary sheet. Sometimes it overlap to second table or have lot of empty rows.

Any help here would appreciated.

Regards,
Waqas
 

Attachments

  • dynamic_ranges.JPG
    dynamic_ranges.JPG
    62 KB · Views: 7

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.
Hi
How about
VBA Code:
Sub test()
    Dim a As Variant
    Dim i, k As Long
    Sheets("Result").Cells.ClearContents
    ReDim a(1 To Sheets.Count - 1)
    For i = 1 To Sheets.Count
        If Sheets(i).Name <> "result" Then
            a(i) = Sheets(i).Range("a1").CurrentRegion
        End If
    Next
    k = 1
    For i = 1 To UBound(a)
        Cells(k, 1).Resize(UBound(a(i)), UBound(a(i), 2)) = a(i)
        k = UBound(a(i)) + k + 2
    Next
End Sub

distination sheets name "Result"
 
Upvote 0
Ver.2
VBA Code:
Sub test()
    Dim a As Variant
    Dim i, k, LR As Long
    k = 1
    Sheets("result").Cells.ClearContents
    For i = 1 To Sheets.Count
        If Sheets(i).Name <> "result" Then
        LR = Sheets(i).Cells(Rows.Count, 1).End(xlUp).Row
            a = Sheets(i).Range("a1").CurrentRegion
            Sheets("result").Cells(k, 1).Resize(UBound(a), UBound(a, 2)) = a
            k = LR + k + 2
        End If
    Next
End Sub
 
Upvote 0
Dear All,

I used Record Marco function to generate this code but I do not know how I can handle summary tab.
I cannot upload my sample file so I am pasting images of different tabs I have.

Rawdata is data I am getting and then Marco based on Criteria tab using advance filter populate Status=Started and Status=Closed tab.
1. I am not able to collect data from both Status tab into Summary tab and dynamically adjust each status table in Summary tab.
2. Plus, I have link column in Rawdata but when I using advance filter, it copy text and formatting but not the link.

Is there any way perhaps to select data from Rawdata directly in Summary tab in different tables dynamic adjust the rows for each table.

Sub Sortdata_v1() ' ' Sortdata_v1 Macro ' ' Range("D5").Select ' As I do know number of rows in Rawdata so I put E column 100 which I think will be max. Ideally, I would like this to adjust as well to last row has data Sheets("Rawdata").Range("A1:E100").AdvancedFilter Action:=xlFilterCopy, _ CriteriaRange:=Sheets("Criteria").Range("A1:B3"), CopyToRange:=Range( _ "'Status=done'!Extract"), Unique:=True Sheets("Status=Closed").Select Range("E5").Select Sheets("Rawdata").Range("A1:E100").AdvancedFilter Action:=xlFilterCopy, _ CriteriaRange:=Sheets("Criteria").Range("E1:E2"), CopyToRange:=Range( _ "A1:E1"), Unique:=True Sheets("Summary").Select Range("G23").Select Sheets("Rawdata").Range("A1:E100").AdvancedFilter Action:=xlFilterCopy, _ CriteriaRange:=Sheets("Criteria").Range("H1:H2"), CopyToRange:=Range( _ "C19:G19"), Unique:=True End Sub

Regards,
Waqas
 

Attachments

  • 1-raw_tab.JPG
    1-raw_tab.JPG
    67.7 KB · Views: 6
  • 2-criteria.JPG
    2-criteria.JPG
    36.3 KB · Views: 7
  • 3-Status.JPG
    3-Status.JPG
    26.8 KB · Views: 6
  • 4-Statusclosed.JPG
    4-Statusclosed.JPG
    25.1 KB · Views: 6
  • 5-Summary.JPG
    5-Summary.JPG
    45.7 KB · Views: 6
Upvote 0
Ver.2
VBA Code:
Sub test()
    Dim a As Variant
    Dim i, k, LR As Long
    k = 1
    Sheets("result").Cells.ClearContents
    For i = 1 To Sheets.Count
        If Sheets(i).Name <> "result" Then
        LR = Sheets(i).Cells(Rows.Count, 1).End(xlUp).Row
            a = Sheets(i).Range("a1").CurrentRegion
            Sheets("result").Cells(k, 1).Resize(UBound(a), UBound(a, 2)) = a
            k = LR + k + 2
        End If
    Next
End Sub
Thanks for the code. I just finished the same activity through Power Query and it works actually I needed.
 
Upvote 0

Forum statistics

Threads
1,224,827
Messages
6,181,194
Members
453,021
Latest member
pingpong7117

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