Consolidate data from multiple ranges from specific worksheets

Negi1984

Board Regular
Joined
May 6, 2011
Messages
198
hi All,

I have a workbook having more than 30 worksheets and increasing on regular basis.
Now every time I have combine data from specific worksheets and multiple ranges based on multiple request from my seniors.

for example : -
1) Sometimes I have to consolidate data from sheet name start with "BKH" or sometimes sheet name start with "AKH" or sometime for "BKH" & "AKH" both. Everytime I am combine it manually.
2) 99% of cases I have to copy data from range of column "B" to "G". and this section is divided into 1-5 sections. and some time from "A" to "F".
3) All sections header contains headers like "item", Item name" or "part number".(here needs to check every time if the range is from A to F or B to G based on first header.
4) while consolidation of all sheets, I need to add sheet name in consolidate sheet.
5) Also I need to add another column while consolidation which contains the "section name" which we find 1 row above each header in each section.

I am also attaching sample file with required result in "Consolidate Data". where data consolidated based on "BKH" only.

Link

Can any body suggest me VBA macro code for the same ?

Thanks in advance.
 

Excel Facts

Easy bullets in Excel
If you have a numeric keypad, press Alt+7 on numeric keypad to type a bullet in Excel.
How do you determine which sheets to use for consolidation?
 
Upvote 0
How do you determine which sheets to use for consolidation?
For this if any message box pop up show to ask which sheets data needs to combine or I can create a table in sheet where I can type which sheet name I have to combine both are ok for me.
 
Upvote 0
Click here to download your file. Just click the "Copy Data" button.
 
Upvote 0
Hi Mumps,

Thanks a lot for your valuable support. just want to looking for small modification instead of each sheet name I need only first 3 letters in pop up window.
and that macro needs to combine data for all the sheets whichever start with 3 letter.
 
Upvote 0
Replace all the macros in the userform code module with the macro below:
VBA Code:
Private Sub CommandButton1_Click()
    Application.ScreenUpdating = False
    Dim c As MSForms.Control, LastRow As Long, i As Long, CFnd As Long, desWS As Worksheet, ws As Worksheet
    Set desWS = Sheets("Consolidate Data")
    For Each c In Me.Controls
        If TypeName(c) = "CheckBox" Then
            If c.Value = True Then
                For Each ws In Sheets
                    If ws.Name Like "*" & c.Caption & "*" Then
                        With ws
                            LastRow = .Cells.Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
                            CFnd = .Cells.Find("section", LookIn:=xlValues, lookat:=xlPart).Column
                            With .Range(.Cells(2, CFnd), .Cells(LastRow, CFnd)).SpecialCells(xlCellTypeConstants)
                                For i = 1 To .Areas.Count
                                    FR = .Areas.Item(i).Row
                                    cnt = .Areas.Item(i).Cells.Count
                                    With desWS
                                        ws.Cells(FR + 2, CFnd).Resize(cnt - 2, 6).Copy .Cells(.Rows.Count, "C").End(xlUp).Offset(1)
                                        .Cells(.Rows.Count, "A").End(xlUp).Offset(1).Resize(cnt - 2) = ws.Name
                                        .Cells(.Rows.Count, "B").End(xlUp).Offset(1).Resize(cnt - 2) = Mid(Cells(FR, CFnd), 11, 9999)
                                    End With
                                Next i
                            End With
                        End With
                    End If
                Next ws
            End If
        End If
    Next c
    Application.ScreenUpdating = True
    Unload Me
End Sub
You will need only this one macro.
 
Upvote 0
Hi Mumps,

I have deleted all the macro from user form code and replace with the above one. but when I am running the above code its not showing first 3 letters of sheet.

Capture.JPG
 
Upvote 0

Forum statistics

Threads
1,214,980
Messages
6,122,563
Members
449,088
Latest member
Motoracer88

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