+ Reply to Thread
Results 1 to 46 of 46

New worksheet based on multiple worksheets

  1. #1
    Registered User
    Join Date
    08-10-2016
    Location
    Ireland
    MS-Off Ver
    2013
    Posts
    67

    New worksheet based on multiple worksheets

    Hi Experts,

    I have two worksheets - "Transactions" and "PO". I need a new sheet to be created on the click of the button.

    This new sheet should be similar to the "Output" sheet. It should have unique Item# and Descriptions along with the more columns added. Columns C:D should be based on "Transactions" sheet and Column H should be based on "PO" sheet. The respective formulae's have been mentioned in the "Output" sheet for your reference.

    Hope I am clear with the requirement. The sample data along with the output has been attached. Please support. Thanks is advance...


    Regards,
    Abhi
    Attached Files Attached Files

  2. #2
    Valued Forum Contributor
    Join Date
    07-14-2017
    Location
    Poland
    MS-Off Ver
    Office 2010
    Posts
    528

    Re: New worksheet based on multiple worksheets

    My attempt.
    Please Login or Register  to view this content.
    Attached Files Attached Files
    Best Regards,
    Maras.

  3. #3
    Forum Expert sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2016 | 2019
    Posts
    13,279

    Re: New worksheet based on multiple worksheets

    Another Option...
    Please Login or Register  to view this content.
    If huge data set, I would do calculation and not use Evaluate...
    Attached Files Attached Files
    Last edited by sintek; 05-16-2021 at 07:07 AM.
    Good Luck
    I don't presume to know what I am doing, however, just like you, I too started somewhere...
    One-day, One-problem at a time!!!
    If you feel I have helped, please click on the star to left of post [Add Reputation]
    Also....add a comment if you like!!!!
    And remember...Mark Thread as Solved.
    Excel Forum Rocks!!!

  4. #4
    Registered User
    Join Date
    08-10-2016
    Location
    Ireland
    MS-Off Ver
    2013
    Posts
    67

    Re: New worksheet based on multiple worksheets

    Many Thanks sintek for your reply.

    The code is working fine for the sample data I provided but if I input the raw data, I am getting the "Run Time Error 13 - Type mismatch".

    The raw data contains thousands of rows and there could be some missing values. Attaching it for your reference.

    Regards,
    Abhi

  5. #5
    Registered User
    Join Date
    08-10-2016
    Location
    Ireland
    MS-Off Ver
    2013
    Posts
    67

    Re: New worksheet based on multiple worksheets

    Many Thanks Maras for your reply.

    The code is working fine for the sample data I provided but the excel is not responding if I input the raw data. The raw data contains thousands of rows and there could be some missing values. Attaching it for your reference.

    Regards,
    Abhi

  6. #6
    Forum Expert sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2016 | 2019
    Posts
    13,279

    Re: New worksheet based on multiple worksheets

    Attaching it for your reference.
    Where.........
    Also very important...In future always upload a sample file depicting your actual file setup so no time is wasted on providing incorrect code...
    Almost all the time the person is not able to amend the code for their actual file...
    Last edited by sintek; 05-17-2021 at 04:46 AM.

  7. #7
    Registered User
    Join Date
    08-10-2016
    Location
    Ireland
    MS-Off Ver
    2013
    Posts
    67

    Re: New worksheet based on multiple worksheets

    Quote Originally Posted by sintek View Post
    Where.........
    Also very important...In future always upload a sample file depicting your actual file setup so no time is wasted on providing incorrect code...
    Almost all the time the person is not able to amend the code for their actual file...
    Apologies for that...actually I didn't realize that my sample data is not depicting the actual data. I am getting the error in the If loop you have provided.

  8. #8
    Forum Expert sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2016 | 2019
    Posts
    13,279

    Re: New worksheet based on multiple worksheets

    I am getting the error in the If loop you have provided.
    I am sure you say you are...I cannot test as I do not have the file you are referencing...

    as per your Post 4
    Attaching it for your reference.
    Where...Nothing was attached...

  9. #9
    Registered User
    Join Date
    08-10-2016
    Location
    Ireland
    MS-Off Ver
    2013
    Posts
    67

    Re: New worksheet based on multiple worksheets

    Quote Originally Posted by sintek View Post
    I am sure you say you are...I cannot test as I do not have the file you are referencing...

    as per your Post 4

    Where...Nothing was attached...
    It's a big file. Attaching it is the binary format. Hope should be fine. Thanks
    Attached Files Attached Files

  10. #10
    Registered User
    Join Date
    08-10-2016
    Location
    Ireland
    MS-Off Ver
    2013
    Posts
    67

    Re: New worksheet based on multiple worksheets

    Hi sintek, I need the unique item# from the "Transactions" data and pull out its info from the "PO" data. Just thought to mention if I was not clear before.
    Many Thanks, Abhi

  11. #11
    Forum Expert sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2016 | 2019
    Posts
    13,279

    Re: New worksheet based on multiple worksheets

    Is because Col A is numbers and texts...
    This will work on small data set but as I mentioned above...For huge datasets it is better to do calculation directly instead of evaluate...
    No time right now but will have a look at it a bit later...
    Please Login or Register  to view this content.

  12. #12
    Registered User
    Join Date
    08-10-2016
    Location
    Ireland
    MS-Off Ver
    2013
    Posts
    67

    Re: New worksheet based on multiple worksheets

    Quote Originally Posted by sintek View Post
    Is because Col A is numbers and texts...
    This will work on small data set but as I mentioned above...For huge datasets it is better to do calculation directly instead of evaluate...
    No time right now but will have a look at it a bit later...
    Hi sintek, I had a thought on how to do the calculations directly as you have suggested for huge datasets but my bad, not able to get it. Can you have a look when you have time please?
    Thanks in advance...Regards, Abhi

  13. #13
    Forum Expert sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2016 | 2019
    Posts
    13,279

    Re: New worksheet based on multiple worksheets

    Can't offhand see any other way of doing some of these calculations as array formulas are required...Perhaps someone else can hop onboard and offer their input...

  14. #14
    Registered User
    Join Date
    08-10-2016
    Location
    Ireland
    MS-Off Ver
    2013
    Posts
    67

    Re: New worksheet based on multiple worksheets

    Quote Originally Posted by maras_mak View Post
    My attempt.
    Please Login or Register  to view this content.
    Hi Maras,

    Today I ran the code again on huge data and amazingly it worked. I left the system idle and it took almost 30 mins to run the code. Is there any way we can optimize the code to run faster? Attaching the data for your reference.

    Thanks,
    Abhi
    Attached Files Attached Files

  15. #15
    Forum Expert sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2016 | 2019
    Posts
    13,279

    Re: New worksheet based on multiple worksheets

    Best I can do is 3 min...Data is sorted Col A lowest to highest...
    Attached Files Attached Files

  16. #16
    Forum Expert sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2016 | 2019
    Posts
    13,279

    Re: New worksheet based on multiple worksheets

    This version takes 101.83 seconds...
    Attached Files Attached Files

  17. #17
    Registered User
    Join Date
    08-10-2016
    Location
    Ireland
    MS-Off Ver
    2013
    Posts
    67

    Re: New worksheet based on multiple worksheets

    Quote Originally Posted by sintek View Post
    This version takes 101.83 seconds...
    This is perfectly working fine. Though for me it is taking around 7 minutes, might be to system configuration. But still manageable.

    One query...what if I want to find the minimum quantity from the "PO" sheet instead of summation, then the code line:

    Application.MinIf(Sheets("PO").Range("C2:C" & lr), Data(i, 1), Sheets("PO").Range("B2:B" & lr))), ";") is not working.

    Is there any other property to find the minimum value?

    Thanks, Abhi

  18. #18
    Forum Expert sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2016 | 2019
    Posts
    13,279

    Re: New worksheet based on multiple worksheets

    Perhaps...
    Please Login or Register  to view this content.

  19. #19
    Registered User
    Join Date
    08-10-2016
    Location
    Ireland
    MS-Off Ver
    2013
    Posts
    67

    Re: New worksheet based on multiple worksheets

    Quote Originally Posted by sintek View Post
    Perhaps...
    Please Login or Register  to view this content.
    With this, I am getting the run-time error - Type mismatch. It seems like I am doing some silly mistake. See attached
    Attached Files Attached Files

  20. #20
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    East Sussex, UK
    MS-Off Ver
    365, varying versions/builds
    Posts
    21,263

    Re: New worksheet based on multiple worksheets

    Administrative Note:

    Welcome to the forum.

    We would very much like to help you with your query, however it has been brought to our attention that the same query has been posted on one or more other forums and you have not provided the required cross-post link(s) here.

    Please see Forum Rule #3 about cross-posting and adjust accordingly. Read this to understand why we (and other sites like us) consider this to be important.

    (Note: this requirement is not optional. No help to be offered until the link is provided.)
    Remember what the dormouse said
    Feed your head

  21. #21
    Registered User
    Join Date
    08-10-2016
    Location
    Ireland
    MS-Off Ver
    2013
    Posts
    67

    Re: New worksheet based on multiple worksheets

    Quote Originally Posted by rorya View Post
    Administrative Note:

    Welcome to the forum.

    We would very much like to help you with your query, however it has been brought to our attention that the same query has been posted on one or more other forums and you have not provided the required cross-post link(s) here.

    Please see Forum Rule #3 about cross-posting and adjust accordingly. Read this to understand why we (and other sites like us) consider this to be important.

    (Note: this requirement is not optional. No help to be offered until the link is provided.)
    Thanks Rory for letting me aware. I missed the forum rules, my sincere apologies. Will be taken care in future.

    Here is the cross-post link but there is no solution posted, and also I have closed the thread over there.

    https://chandoo.org/forum/threads/cr...ksheets.46305/

    Thanks again. ..Abhi

  22. #22
    Forum Expert sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2016 | 2019
    Posts
    13,279

    Re: New worksheet based on multiple worksheets

    With this, I am getting the run-time error - Type mismatch
    See attached....
    Attached Files Attached Files

  23. #23
    Forum Expert dangelor's Avatar
    Join Date
    09-06-2011
    Location
    Indiana, USA
    MS-Off Ver
    365 Pro Plus
    Posts
    2,274

    Re: New worksheet based on multiple worksheets

    This code took a little under 3 seconds on my laptop...
    Please Login or Register  to view this content.
    Attached Files Attached Files
    Last edited by dangelor; 05-18-2021 at 01:30 PM.

  24. #24
    Registered User
    Join Date
    08-10-2016
    Location
    Ireland
    MS-Off Ver
    2013
    Posts
    67

    Re: New worksheet based on multiple worksheets

    Quote Originally Posted by sintek View Post
    See attached....
    Woww. This has solved my query. You're superb. Thanks Man.

  25. #25
    Forum Expert sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2016 | 2019
    Posts
    13,279

    Re: New worksheet based on multiple worksheets

    @dangelor...Nicely done...

  26. #26
    Forum Expert dangelor's Avatar
    Join Date
    09-06-2011
    Location
    Indiana, USA
    MS-Off Ver
    365 Pro Plus
    Posts
    2,274

    Re: New worksheet based on multiple worksheets

    Just a different approach... Thanks for the compliment and the rep!

  27. #27
    Registered User
    Join Date
    08-10-2016
    Location
    Ireland
    MS-Off Ver
    2013
    Posts
    67

    Re: New worksheet based on multiple worksheets

    Quote Originally Posted by sintek View Post
    See attached....
    Hi Sintek,

    The code is working fine for most of the dataset. But for some items it is pulling the false descriptions and for few items, the descriptions got split into columns.
    See attached....The "Transactions" sheet only contains the data in which I am getting the wrong output.

    Just wondering why it is only for few items and only with descriptions, something strange for me.

    Thanks, Abhi
    Attached Files Attached Files

  28. #28
    Forum Expert sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2016 | 2019
    Posts
    13,279

    Re: New worksheet based on multiple worksheets

    Why not go with dangelor solution...

  29. #29
    Registered User
    Join Date
    08-10-2016
    Location
    Ireland
    MS-Off Ver
    2013
    Posts
    67

    Re: New worksheet based on multiple worksheets

    Quote Originally Posted by sintek View Post
    Why not go with dangelor solution...
    Let me see that way if it works...thanks

  30. #30
    Registered User
    Join Date
    08-10-2016
    Location
    Ireland
    MS-Off Ver
    2013
    Posts
    67

    Re: New worksheet based on multiple worksheets

    Quote Originally Posted by dangelor View Post
    This code took a little under 3 seconds on my laptop...
    Please Login or Register  to view this content.
    Hi dangelor,

    As sintek recommended, I am using your solution. The code is absolutely working fine on my raw dataset. Can you please suggest on how to add two more columns in the "Output" sheet for minimum and average of the quantities from the "PO" sheet? Apologies if I was not clear at the first instant.

    Many Thanks, Abhi

  31. #31
    Registered User
    Join Date
    08-10-2016
    Location
    Ireland
    MS-Off Ver
    2013
    Posts
    67

    Re: New worksheet based on multiple worksheets

    Quote Originally Posted by abhi_jain80 View Post
    Hi dangelor,

    As sintek recommended, I am using your solution. The code is absolutely working fine on my raw dataset. Can you please suggest on how to add two more columns in the "Output" sheet for minimum and average of the quantities from the "PO" sheet? Apologies if I was not clear at the first instant.

    Many Thanks, Abhi
    Hi Dangelor,

    I have tried to add one more column in the output for average quantity ordered, but my bad...not getting the accurate results. I know I am doing some silly mistake, can you please have a look when you have time please?

    'Average Quantity Ordered
    v = Sheet4.Cells(1).CurrentRegion
    With CreateObject("Scripting.Dictionary")
    For i = 2 To UBound(v)
    If .Item(v(i, 3)) Then
    .Item(v(i, 3)) = WorksheetFunction.Average(.Item(v(i, 3)), v(i, 2))
    Else
    .Item(v(i, 3)) = v(i, 2)
    End If
    Next i
    For i = 2 To UBound(sku1)
    sku1(i, 1) = .Item(sku1(i, 1))
    Next i
    Sheet1.Columns(9).NumberFormat = "0.00"
    Sheet1.Cells(1, 9).Resize(i - 1) = sku1
    Sheet1.Cells(1, 9) = "Avg Qty"
    End With

    Thanks, Abhi
    Attached Files Attached Files

  32. #32
    Forum Expert dangelor's Avatar
    Join Date
    09-06-2011
    Location
    Indiana, USA
    MS-Off Ver
    365 Pro Plus
    Posts
    2,274

    Re: New worksheet based on multiple worksheets

    When I can..

  33. #33
    Registered User
    Join Date
    08-10-2016
    Location
    Ireland
    MS-Off Ver
    2013
    Posts
    67

    Re: New worksheet based on multiple worksheets

    Quote Originally Posted by dangelor View Post
    When I can..
    Thanks dangelor for your support. Also just I observed that the average cost for some items are not coming accurate, for ex: for Item# 22300405, the average cost coming in output as 124.2004, while actually it is 120.29. Please look into this also. Thank you.

    Regards, Abhi
    Attached Files Attached Files

  34. #34
    Forum Expert dangelor's Avatar
    Join Date
    09-06-2011
    Location
    Indiana, USA
    MS-Off Ver
    365 Pro Plus
    Posts
    2,274

    Re: New worksheet based on multiple worksheets

    I noticed that last night. Still working it, but life interrupts at times...

  35. #35
    Registered User
    Join Date
    08-10-2016
    Location
    Ireland
    MS-Off Ver
    2013
    Posts
    67

    Re: New worksheet based on multiple worksheets

    Quote Originally Posted by dangelor View Post
    I noticed that last night. Still working it, but life interrupts at times...
    Yes, I can understand. Believe me, I spent around 14 hours on this but could not be able to figure out the solution

  36. #36
    Forum Expert dangelor's Avatar
    Join Date
    09-06-2011
    Location
    Indiana, USA
    MS-Off Ver
    365 Pro Plus
    Posts
    2,274

    Re: New worksheet based on multiple worksheets

    Sorry for the delay... finally got the average right, and it's a bit slower.
    Please Login or Register  to view this content.
    Attached Files Attached Files
    Last edited by dangelor; 05-25-2021 at 10:23 PM.

  37. #37
    Registered User
    Join Date
    08-10-2016
    Location
    Ireland
    MS-Off Ver
    2013
    Posts
    67

    Re: New worksheet based on multiple worksheets

    Quote Originally Posted by dangelor View Post
    Sorry for the delay... finally got the average right, and it's a bit slower.
    Please Login or Register  to view this content.
    Thanks dangelor for working on this, but apologies as still I am seeing the inaccurate average for some of the items.
    for ex: the average cost in the output for item# 22300403 is 118.54 but actually it is 119.66. Similarly for 22300404, in output it's coming as 131.98 and actually it is 133.10

    Thanks, Abhi

  38. #38
    Forum Expert dangelor's Avatar
    Join Date
    09-06-2011
    Location
    Indiana, USA
    MS-Off Ver
    365 Pro Plus
    Posts
    2,274

    Re: New worksheet based on multiple worksheets

    When I run the numbers (Total cost / Total qty) manually for those two items, I get the averages listed by the code.

  39. #39
    Registered User
    Join Date
    08-10-2016
    Location
    Ireland
    MS-Off Ver
    2013
    Posts
    67

    Re: New worksheet based on multiple worksheets

    Quote Originally Posted by dangelor View Post
    When I run the numbers (Total cost / Total qty) manually for those two items, I get the averages listed by the code.
    My bad...I figured out my mistake. Thank you so much.

    Something weird I have observed today. Most of the dates outputted in the "First Issue Date" are in right date format but few came in text format...like over here for item# 22300406 and 22300420, the dates are in text format while in the base data, all are in the correct date format. Might you are aware of the quick solution for this.

  40. #40
    Forum Expert dangelor's Avatar
    Join Date
    09-06-2011
    Location
    Indiana, USA
    MS-Off Ver
    365 Pro Plus
    Posts
    2,274

    Re: New worksheet based on multiple worksheets

    Try it this way...
    Please Login or Register  to view this content.

  41. #41
    Registered User
    Join Date
    08-10-2016
    Location
    Ireland
    MS-Off Ver
    2013
    Posts
    67

    Re: New worksheet based on multiple worksheets

    Quote Originally Posted by dangelor View Post
    Try it this way...
    Please Login or Register  to view this content.
    Still the same issue. I realize that the dates are not in the date format where there is only one transaction. see attached...thanks
    Attached Files Attached Files

  42. #42
    Forum Expert dangelor's Avatar
    Join Date
    09-06-2011
    Location
    Indiana, USA
    MS-Off Ver
    365 Pro Plus
    Posts
    2,274

    Re: New worksheet based on multiple worksheets

    Try changing the date formatting...
    Please Login or Register  to view this content.

  43. #43
    Registered User
    Join Date
    08-10-2016
    Location
    Ireland
    MS-Off Ver
    2013
    Posts
    67

    Re: New worksheet based on multiple worksheets

    Quote Originally Posted by dangelor View Post
    Try changing the date formatting...
    Please Login or Register  to view this content.
    I changed the date format to "d/m/yyyy" but sorry to say, still the same problem

  44. #44
    Forum Expert dangelor's Avatar
    Join Date
    09-06-2011
    Location
    Indiana, USA
    MS-Off Ver
    365 Pro Plus
    Posts
    2,274

    Re: New worksheet based on multiple worksheets

    I don't know what could be causing it. It doesn't happen on my systems.

  45. #45
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Lightbulb Try this !


    Hi,

    same issue 'cause of the classic trap of a range without any property …

    Solved on my side with vT = Range("Transactions!A1").CurrentRegion.Value2
    Last edited by Marc L; 05-31-2021 at 12:12 PM.

  46. #46
    Registered User
    Join Date
    08-10-2016
    Location
    Ireland
    MS-Off Ver
    2013
    Posts
    67

    Re: Try this !

    Quote Originally Posted by Marc L View Post

    Hi,

    same issue 'cause of the classic trap of a range without any property …

    Solved on my side with vT = Range("Transactions!A1").CurrentRegion.Value2
    Great Marc, this has solved my issue. Thank you so much.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Splitting Worksheet into multiple worksheets based on Column
    By bfaws in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 02-25-2021, 12:38 PM
  2. [SOLVED] Create New Worksheet based on duplicates in Multiple worksheets
    By a1cswiz in forum Excel Programming / VBA / Macros
    Replies: 18
    Last Post: 04-24-2019, 03:07 AM
  3. Split worksheet into multiple worksheets based on value in column A (BUT more complicated)
    By carlito2002wgn in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 02-27-2019, 05:10 PM
  4. Save WorkSheets to Multiple Folders based on the WorkSheet Name
    By HangMan in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 10-25-2015, 03:20 PM
  5. VBA: send row to another worksheet and copy row to multiple worksheets based on column
    By catherineburns in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 07-18-2014, 08:51 AM
  6. [SOLVED] How to split worksheet into multiple worksheets based on column content
    By Laurelmzitney in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 06-03-2014, 10:57 AM
  7. Replies: 0
    Last Post: 03-17-2014, 12:43 PM

Tags for this Thread

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1