Consulting

Results 1 to 5 of 5

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

  1. #1

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

    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
    Last edited by ShadowySin; 04-01-2018 at 12:48 AM.

  2. #2
    Knowledge Base Approver VBAX Wizard p45cal's Avatar
    Joined
    Oct 2005
    Location
    Surrey UK
    Posts
    5,924
    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.
    p45cal
    Everyone: If I've helped and you can't be bothered to acknowledge it, I can't be bothered to look at further posts from you.

  3. #3
    Quote Originally Posted by ShadowySin View Post
    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/h...-same-workbook.
    https://www.mrexcel.com/forum/excel-...ml#post5041590
    Attached Files Attached Files
    Last edited by ShadowySin; 04-01-2018 at 07:39 AM.

  4. #4
    Knowledge Base Approver VBAX Wizard p45cal's Avatar
    Joined
    Oct 2005
    Location
    Surrey UK
    Posts
    5,924
    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!)
    Attached Files Attached Files
    p45cal
    Everyone: If I've helped and you can't be bothered to acknowledge it, I can't be bothered to look at further posts from you.

  5. #5
    Thank you!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •