PDA

View Full Version : #1 VBA to sort data from multiple worksheets into a worksheet (same workbook)



ShadowySin
03-31-2018, 11:38 PM
Hi, I need help to create a macro using vba to sort out data. There are many worksheets containing date&time values and for each worksheet, I have to sort out the data. Those with identical date&time values are classified as dual and those with only one date&time value are classified as single. I need to count how many single, how many dual and total number of single and dual for each day. The thing is that I need to code it such that when I set my date parameters such as 1st feb 2018 to 28th feb 2018, only the dates that are inside my data get selected. As you can see from below, the first example is what my data looks like on one worksheet while the other example is what I want to achieve on my analysis worksheet. Basically, the id is my worksheet name and (01-Feb 2018 12:00) is a dual while (01-Feb 2018 13:30) is a single, with 03-Feb not appearing in my analysis because it is not inside the data even though it is within my search parameters.
For example, on A1, 01-feb, there are 2 singles and 1 dual for a total of 3 which means that average is 4/3=1.33

date
01-Feb 2018 12:00
01-Feb 2018 12:00
01-Feb 2018 13:30
01-Feb 2018 14:00
02-Feb 2018 08:00
02-Feb 2018 08:00
08-Feb 2018 07:00
worksheet A1

Search parameters: 01-Feb 2018 to 28-Feb 2018

ID DATE TOTAL DUAL SIN AVG
A1 01-Feb 03 01 02 1.33
A1 02-Feb 19 10 09 1.53
A1 08-Feb 19 09 10 1.47
A1 15-Feb 30 24 06 1.80
A1 18-Feb 25 16 09 1.64
A1 21-Feb 17 12 05 1.71
A2 04-Feb 15 09 06 1.60
A2 08-Feb 18 12 06 1.67
A2 19-Feb 26 20 06 1.77
A2 20-Feb 19 17 02 1.90
A2 21-Feb 40 38 02 1.95
A3 12-Feb 34 32 02 1.94
worksheet analysis

I got the above data by doing it manually which was super troublesome and time consuming so i was wondering if you guys could help me. Thank you

p45cal
04-01-2018, 03:25 AM
1. Supply a workbook with this sort of stuff in so that we can experiment.
2. You've cross posted this elsewhere. Have a read of http://www.excelguru.ca/content.php?184 then add links here and at the other forum(s) - they have the same netiquette rules.

ShadowySin
04-01-2018, 07:01 AM
Hi, I need help to create a macro using vba to sort out data. There are many worksheets containing date&time values and for each worksheet, I have to sort out the data. Those with identical date&time values are classified as dual and those with only one date&time value are classified as single. I need to count how many single, how many dual and total number of single and dual for each day. The thing is that I need to code it such that when I set my date parameters such as 1st feb 2018 to 28th feb 2018, only the dates that are inside my data get selected. As you can see from below, the first example is what my data looks like on one worksheet while the other example is what I want to achieve on my analysis worksheet. Basically, the id is my worksheet name and (01-Feb 2018 12:00) is a dual while (01-Feb 2018 13:30) is a single, with 03-Feb not appearing in my analysis because it is not inside the data even though it is within my search parameters.
For example, on A1, 01-feb, there are 2 singles and 1 dual for a total of 3 which means that average is 4/3=1.33

date
01-Feb 2018 12:00
01-Feb 2018 12:00
01-Feb 2018 13:30
01-Feb 2018 14:00
02-Feb 2018 08:00
02-Feb 2018 08:00
08-Feb 2018 07:00
worksheet A1

Search parameters: 01-Feb 2018 to 28-Feb 2018

ID DATE TOTAL DUAL SIN AVG
A1 01-Feb 03 01 02 1.33
A1 02-Feb 19 10 09 1.53
A1 08-Feb 19 09 10 1.47
A1 15-Feb 30 24 06 1.80
A1 18-Feb 25 16 09 1.64
A1 21-Feb 17 12 05 1.71
A2 04-Feb 15 09 06 1.60
A2 08-Feb 18 12 06 1.67
A2 19-Feb 26 20 06 1.77
A2 20-Feb 19 17 02 1.90
A2 21-Feb 40 38 02 1.95
A3 12-Feb 34 32 02 1.94
worksheet analysis

I got the above data by doing it manually which was super troublesome and time consuming so i was wondering if you guys could help me. Thank you

I have no idea why I cant edit my post so I'll just state it here. Attached is a sample of a workbook.
My links to posts in other forums are:
https://www.excelforum.com/excel-programming-vba-macros/1226145-vba-to-sort-data-from-multiple-worksheets-and-compile-into-a-worksheet-all-same-workbook.html#post4875136
https://www.ozgrid.com/forum/forum/help-forums/excel-vba-macros/1201820-vba-to-sort-data-from-multiple-worksheets-into-a-worksheet-same-workbook.
https://www.mrexcel.com/forum/excel-questions/1049981-vba-sort-data-multiple-worksheets-compile-into-worksheet-all-same-workbook.html#post5041590

p45cal
04-01-2018, 04:03 PM
In the attached there's a button to click which calls macro blah.
Not 100% sure I have this right as it gives different results for Feb 3rd; could you check?
I've left your manual results at row 14 of Sheet1 for comparison.
Comments in code about which sheets to process; is there a sheet naming convention you have so that we can decide which sheets to process? If not perhaps we could use the fact that there's always 'Start date' in cell A1 in all the sheets that need to be processed?

(Saved you $20!)

ShadowySin
04-02-2018, 05:53 AM
Thank you!