Summarize Data from different Sheets via VBA

BIGTONE559

Active Member
Joined
Apr 20, 2011
Messages
336
I'm in need of Help/Direction with trying to summarize data in multiple worksheets. The idea is to create a "summarypage" of the data on the 5 sheets. The position of the date remains constant. The Color/Descrip/Qty are all variables. On the summary page the items are grouped by date and displayed beginning in cell "A6". . .

Please Help

%3E%3Ctable%20border=%221%22%20cellspacing=%220%22%20cellpadding=%220%22%20style=%22font-family:Calibri,Arial;%20font-size:11pt;%20background-color:

%3E%3Ctable%20border=%221%22%20cellspacing=%220%22%20cellpadding=%220%22%20style=%22font-family:Calibri,Arial;%20font-size:11pt;%20background-color:

%3E%3Ctable%20border=%221%22%20cellspacing=%220%22%20cellpadding=%220%22%20style=%22font-family:Calibri,Arial;%20font-size:11pt;%20background-color:

%3E%3Ctable%20border=%221%22%20cellspacing=%220%22%20cellpadding=%220%22%20style=%22font-family:Calibri,Arial;%20font-size:11pt;%20background-color:
 
Last edited:
Hi,

For the macro to work please follow the folowing steps:

1. The sheets(1-4) must follow the format you setup in sheet2
2. Leave sheet "summary" completely empty
3. Go to macro-record macro-stop macro
4. Paste the code on the newly created macro.

Cheers!

Rotimi
 
Upvote 0

Excel Facts

Highlight Duplicates
Home, Conditional Formatting, Highlight Cells, Duplicate records, OK to add pink formatting to any duplicates in selected range.
Akinrotimi,

You are missing the beginning of your code:
Sub Name_Of_Macro()

It would also help when you post code, that you wrap the code in code tags.

If posting VBA code, please use Code Tags, see below in my Signature block: If posting VBA code, please use Code Tags - like this



BIGTONE559,

Can we have a screenshot of what the Summary sheet should look like after a macro?
 
Upvote 0
BIGTONE559,


The idea is to create a "summarypage" of the data on the 5 sheets.

You have supplied screenshots of only 4 of the 5 worksheets. Can we have a screenshot of Sheet5?


On the summary page the items are grouped by date and displayed beginning in cell "A6". . .

On the screenshot of worksheet Summary, your raw data should begin in cell A8?
 
Upvote 0
BIGTONE559,


Sample worksheets:


Excel Workbook
ABCD
1Summary Page
2
3
4
5
6
7DatesColorDescriptionQTY
8
9
10
11
12
13
14
15
16
17
18
19
20
Summary





Excel Workbook
ABCD
7
8Date7/3/2011
9ColorDescripQty
10GreenPie12
11YellowCake13
12RedIce Cream174
13BrownTwinkie19
14
Sheet2





Excel Workbook
ABCD
7
87/1/2011
9
10GreenLollipop12
11YellowSnickers13
12RedCake174
13BrownSnickers19
14
Sheet3





Excel Workbook
ABCD
7
87/2/2011
9
10GreenLollipop15
11YellowSnickers21
12RedCake485
13BrownSnickers12
14
Sheet4





After the macro in worksheet Summary:


Excel Workbook
ABCD
1Summary Page
2
3
4
5
6
7DatesColorDescriptionQTY
87/3/2011GreenPie12
97/3/2011YellowCake13
107/3/2011RedIce Cream174
117/3/2011BrownTwinkie19
127/1/2011GreenLollipop12
137/1/2011YellowSnickers13
147/1/2011RedCake174
157/1/2011BrownSnickers19
167/2/2011GreenLollipop15
177/2/2011YellowSnickers21
187/2/2011RedCake485
197/2/2011BrownSnickers12
20
Summary





Please TEST this FIRST in a COPY of your workbook (always make a backup copy before trying new code, you never know what you might lose).

1. Copy the below code, by highlighting the code and pressing the keys CTRL + C
2. Open your workbook
3. Press the keys ALT + F11 to open the Visual Basic Editor
4. Press the keys ALT + I to activate the Insert menu
5. Press M to insert a Standard Module
6. Where the cursor is flashing, paste the code by pressing the keys CTRL + V
7. Press the keys ALT + Q to exit the Editor, and return to Excel
8. To run the macro from Excel, open the workbook, and press ALT + F8 to display the Run Macro Dialog. Double Click the macro's name to Run it.


Code:
Option Explicit
Sub SummarizeData()
' hiker95, 08/10/2011
' http://www.mrexcel.com/forum/showthread.php?t=570236
Dim wSum As Worksheet, ws As Worksheet
Dim LR As Long, NR As Long
Application.ScreenUpdating = False
Set wSum = Worksheets("Summary")
For Each ws In ThisWorkbook.Worksheets
  If ws.Name <> "Summary" Then
    With ws
      LR = ws.Cells(Rows.Count, 1).End(xlUp).Row
      NR = wSum.Range("A" & Rows.Count).End(xlUp).Offset(1).Row
      wSum.Range("A" & NR).Resize(LR - 9).Value = ws.Range("D8").Value
      wSum.Range("B" & NR).Resize(LR - 9, 3).Value = ws.Range("A10:C" & LR).Value
    End With
  End If
Next ws
wSum.Activate
Application.ScreenUpdating = True
End Sub


Before you use the macro with Excel 2007 or newer, save your workbook, Save As, a macro enabled workbook with the file extension .xlsm


Then run the SummarizeData macro.
 
Upvote 0
BIGTONE559,

If you need the data in worksheet Summary sorted, then let me know how you want the data sorted.
 
Upvote 0
Hiker,

Thanks for putting me through on d coding link here.Please kindly test my code and confirm whether it is working.
I told him to insert the code appropriately thereby makind the code name irrelevelant.I however accept all your explanations on this.Please test my code and confirmed whether it did work.

Thanks

Rotimi
 
Upvote 0
BIGTONE559,


BIGTONE559,


Sorry, I missed your worksheet Sheet1 screenshot.


Sample worksheets:


Excel Workbook
ABCD
1Summary Page
2
3
4
5
6
7DatesColorDescriptionQTY
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
Summary





Excel Workbook
ABCD
7
87/2/2011
9
10GreenLollipopBig15
11YellowSnickersSmall21
12RedCakeMedium485
13BrownSnickersBig12
14
Sheet1





Excel Workbook
ABCD
7
8Date7/3/2011
9ColorDescripQty
10GreenPie12
11YellowCake13
12RedIce Cream174
13BrownTwinkie19
14
Sheet2





Excel Workbook
ABCD
7
87/1/2011
9
10GreenLollipop12
11YellowSnickers13
12RedCake174
13BrownSnickers19
14
Sheet3





Excel Workbook
ABCD
7
87/2/2011
9
10GreenLollipop15
11YellowSnickers21
12RedCake485
13BrownSnickers12
14
Sheet4





After the macro:


Excel Workbook
ABCD
1Summary Page
2
3
4
5
6
7DatesColorDescriptionQTY
87/2/2011GreenLollipop15
97/2/2011YellowSnickers21
107/2/2011RedCake485
117/2/2011BrownSnickers12
127/3/2011GreenPie12
137/3/2011YellowCake13
147/3/2011RedIce Cream174
157/3/2011BrownTwinkie19
167/1/2011GreenLollipop12
177/1/2011YellowSnickers13
187/1/2011RedCake174
197/1/2011BrownSnickers19
207/2/2011GreenLollipop15
217/2/2011YellowSnickers21
227/2/2011RedCake485
237/2/2011BrownSnickers12
24
Summary





Please TEST this FIRST in a COPY of your workbook (always make a backup copy before trying new code, you never know what you might lose).

1. Copy the below code, by highlighting the code and pressing the keys CTRL + C
2. Open your workbook
3. Press the keys ALT + F11 to open the Visual Basic Editor
4. Press the keys ALT + I to activate the Insert menu
5. Press M to insert a Standard Module
6. Where the cursor is flashing, paste the code by pressing the keys CTRL + V
7. Press the keys ALT + Q to exit the Editor, and return to Excel
8. To run the macro from Excel, open the workbook, and press ALT + F8 to display the Run Macro Dialog. Double Click the macro's name to Run it.


Code:
Option Explicit
Sub SummarizeDataV2()
' hiker95, 08/11/2011
' http://www.mrexcel.com/forum/showthread.php?t=570236
Dim wSum As Worksheet, ws As Worksheet
Dim LR As Long, NR As Long
Application.ScreenUpdating = False
Set wSum = Worksheets("Summary")
For Each ws In ThisWorkbook.Worksheets
  If ws.Name <> "Summary" Then
    If ws.Name = "Sheet1" Then
      With ws
        LR = ws.Cells(Rows.Count, 1).End(xlUp).Row
        NR = wSum.Range("A" & Rows.Count).End(xlUp).Offset(1).Row
        wSum.Range("A" & NR).Resize(LR - 9).Value = ws.Range("D8").Value
        wSum.Range("B" & NR).Resize(LR - 9, 2).Value = ws.Range("A10:B" & LR).Value
        wSum.Range("D" & NR).Resize(LR - 9).Value = ws.Range("D10:D" & LR).Value
      End With
    Else
      With ws
        LR = ws.Cells(Rows.Count, 1).End(xlUp).Row
        NR = wSum.Range("A" & Rows.Count).End(xlUp).Offset(1).Row
        wSum.Range("A" & NR).Resize(LR - 9).Value = ws.Range("D8").Value
        wSum.Range("B" & NR).Resize(LR - 9, 3).Value = ws.Range("A10:C" & LR).Value
      End With
    End If
  End If
Next ws
LR = wSum.Cells(Rows.Count, 1).End(xlUp).Row
wSum.Range("A8:A" & LR).NumberFormat = "m/d/yyyy"
wSum.Activate
Application.ScreenUpdating = True
End Sub


Before you use the macro with Excel 2007 or newer, save your workbook, Save As, a macro enabled workbook with the file extension .xlsm


Then run the SummarizeDataV2 macro.
 
Upvote 0
Akinrotimi,

Thanks for putting me through on d coding link here.Please kindly test my code and confirm whether it is working.


If you post all of your macro code (including the name of the macro), using code tags , I would be happy to test it for you.
 
Upvote 0

Forum statistics

Threads
1,224,578
Messages
6,179,654
Members
452,934
Latest member
mm1t1

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