+ Reply to Thread
Results 1 to 34 of 34

Need to add code to add an extra sheet with condition

  1. #1
    Forum Contributor
    Join Date
    11-25-2021
    Location
    INDIA
    MS-Off Ver
    2007
    Posts
    2,147

    Need to add code to add an extra sheet with condition

    Hello Experts
    I have this application which combined the data of 3 sheets from source sheet, after some conditions are fulfilled in a new workbook. This time I received a data which has an additional sheet (cdnur) in the source file. I need your expertise to help me to add the data of 4th sheet in the destination sheet last empty row with some conditions. I am sharing the expected result in the file for reference.
    Please note that there are 2 sheets shared one is the source which should be closed when running the macro and the other where the button is to play the code.
    Thank you in advance.
    Sorry forgot to change the amounts to negative in the sample expected sheet. The figures to be in negative.
    Attached Files Attached Files
    Last edited by RAJESH SHAH; 04-30-2023 at 03:29 PM. Reason: #Solved by John Topley
    "There is nothing called problem, it's just absence of an idea to find*solution."
    ?I have not failed. I?ve just found 10,000 ways that won?t work.?
    ?Thomas Edison

  2. #2
    Forum Expert
    Join Date
    05-05-2015
    Location
    UK
    MS-Off Ver
    Microsoft Excel for Microsoft 365 MSO (Version 2402 Build 16.0.17328.20068) 64-bit
    Posts
    28,209

    Re: Need to add code to add an extra sheet with condition

    Yet again, a lack of explanattion:
    with some conditions
    So what are they ?

    Sheet "cdnur" column A has data "EXPWOP" but in "Combined Invoices" w/book it is (or appears to be) "URP" .etc
    If that takes care of your original question, please select Thread Tools from the menu link above and mark this thread as SOLVED.

  3. #3
    Forum Contributor
    Join Date
    11-25-2021
    Location
    INDIA
    MS-Off Ver
    2007
    Posts
    2,147

    Re: Need to add code to add an extra sheet with condition

    Quote Originally Posted by JohnTopley View Post
    Yet again, a lack of explanattion:

    So what are they ?

    Sheet "cdnur" column A has data "EXPWOP" but in "Combined Invoices" w/book it is (or appears to be) "URP" .etc
    I want URP in place of EXPWOP.I tried editing the code but was not getting it right. Please edit the same code as it is easy to understand. I have missed something which I am not able to understand. See the edited code I tried.
    Please Login or Register  to view this content.
    Last edited by RAJESH SHAH; 04-30-2023 at 01:06 PM.

  4. #4
    Forum Expert
    Join Date
    05-05-2015
    Location
    UK
    MS-Off Ver
    Microsoft Excel for Microsoft 365 MSO (Version 2402 Build 16.0.17328.20068) 64-bit
    Posts
    28,209

    Re: Need to add code to add an extra sheet with condition

    Removed by JT

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

    Re: Need to add code to add an extra sheet with condition

    And yet again...Another 40 post thread coming up...
    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!!!

  6. #6
    Forum Contributor
    Join Date
    11-25-2021
    Location
    INDIA
    MS-Off Ver
    2007
    Posts
    2,147

    Re: Need to add code to add an extra sheet with condition

    I have corrected one mistake in the above code. I have replaced "=cdnr" at all places with "=cdnur" but still not getting the expected result.

  7. #7
    Forum Contributor
    Join Date
    11-25-2021
    Location
    INDIA
    MS-Off Ver
    2007
    Posts
    2,147

    Re: Need to add code to add an extra sheet with condition

    Not funny sintek. I have threads which were solved in 2 or 3 posts only.

  8. #8
    Forum Contributor
    Join Date
    11-25-2021
    Location
    INDIA
    MS-Off Ver
    2007
    Posts
    2,147

    Re: Need to add code to add an extra sheet with condition

    After further deleting, I got the display in the required columns except for column I and one more thing is missing as the cdnr rows are overwriting the sxpo rows. I removed the lines of a few columns showing blank which were not important for now.
    Please Login or Register  to view this content.

  9. #9
    Forum Expert
    Join Date
    05-05-2015
    Location
    UK
    MS-Off Ver
    Microsoft Excel for Microsoft 365 MSO (Version 2402 Build 16.0.17328.20068) 64-bit
    Posts
    28,209

    Re: Need to add code to add an extra sheet with condition

    Further confused as code is in "Combined...." yet data sheets referenced by the code are in "EINV..."

    If data is being overwritten it suggest the "lastrow" code is wrong or missing.

  10. #10
    Forum Contributor
    Join Date
    11-25-2021
    Location
    INDIA
    MS-Off Ver
    2007
    Posts
    2,147

    Re: Need to add code to add an extra sheet with condition

    Please Login or Register  to view this content.
    This line is printing URP but overwriting the exp rows. That is what I am wondering what I missed to avoid overwriting.

  11. #11
    Forum Expert
    Join Date
    05-05-2015
    Location
    UK
    MS-Off Ver
    Microsoft Excel for Microsoft 365 MSO (Version 2402 Build 16.0.17328.20068) 64-bit
    Posts
    28,209

    Re: Need to add code to add an extra sheet with condition

    Use Debug.print to ascertain the various row counts (Lastrow) values.

  12. #12
    Forum Contributor
    Join Date
    11-25-2021
    Location
    INDIA
    MS-Off Ver
    2007
    Posts
    2,147

    Re: Need to add code to add an extra sheet with condition

    Got most of the columns right without overwriting but I am getting a value error in column I of URP rows. This is the only issue pending to be solved. I have attached an image of the result.

    Please Login or Register  to view this content.
    Attachment 827604

  13. #13
    Forum Expert
    Join Date
    05-05-2015
    Location
    UK
    MS-Off Ver
    Microsoft Excel for Microsoft 365 MSO (Version 2402 Build 16.0.17328.20068) 64-bit
    Posts
    28,209

    Re: Need to add code to add an extra sheet with condition

    Cannot view attachments!

    Looking at sheet "ws_b2b_sez_de" column I is TEXT ("Invoice Type") for perhaps it should be column L ("Taxable Value") or from L to ?


    Please Login or Register  to view this content.

  14. #14
    Forum Contributor
    Join Date
    11-25-2021
    Location
    INDIA
    MS-Off Ver
    2007
    Posts
    2,147

    Re: Need to add code to add an extra sheet with condition

    Column L in "ws_b2b_sez_de" is Invoice type and ws_cdnur column D is the same (Note Type). It is C in column D which has to be entered as Credit Note in column L of "ws_b2b_sez_de" sheet.

  15. #15
    Forum Expert
    Join Date
    05-05-2015
    Location
    UK
    MS-Off Ver
    Microsoft Excel for Microsoft 365 MSO (Version 2402 Build 16.0.17328.20068) 64-bit
    Posts
    28,209

    Re: Need to add code to add an extra sheet with condition

    In workbook "EINV ...." sheet "b2b, sez, de" column I is "Invoice Type": you miss the point that the error is in the calculation I posted in the last post.

    Another example here of crossed swords as we appear to be referring to different w/books!!!!
    Last edited by JohnTopley; 04-30-2023 at 03:19 PM.

  16. #16
    Forum Contributor
    Join Date
    11-25-2021
    Location
    INDIA
    MS-Off Ver
    2007
    Posts
    2,147

    Re: Need to add code to add an extra sheet with condition

    Quote Originally Posted by JohnTopley View Post
    Cannot view attachments!

    Looking at sheet "ws_b2b_sez_de" column I is TEXT ("Invoice Type") for perhaps it should be column L ("Taxable Value") or from L to ?


    Please Login or Register  to view this content.
    Looking into it. I think you are right.

  17. #17
    Forum Contributor
    Join Date
    11-25-2021
    Location
    INDIA
    MS-Off Ver
    2007
    Posts
    2,147

    Re: Need to add code to add an extra sheet with condition

    Clumsy of me. I got it right now. You can tale back your sword frpm my neck now.😜
    Thanks John Topley. It is solved now. ").

  18. #18
    Forum Expert
    Join Date
    05-05-2015
    Location
    UK
    MS-Off Ver
    Microsoft Excel for Microsoft 365 MSO (Version 2402 Build 16.0.17328.20068) 64-bit
    Posts
    28,209

    Re: Need to add code to add an extra sheet with condition

    In future, just spend a little more time investigating your problem(s) before putting fingers to keyboard Testing as as much a skill as coding.

  19. #19
    Forum Contributor
    Join Date
    11-25-2021
    Location
    INDIA
    MS-Off Ver
    2007
    Posts
    2,147

    Re: Need to add code to add an extra sheet with condition

    Quote Originally Posted by sintek View Post
    And yet again...Another 40 post thread coming up...
    Solved in less than half of 40 posts. 😜 After viewing JohnnyL's comments it took 5 hours to edit this one code. You should understand I am a bit slow at understanding.

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

    Re: Need to add code to add an extra sheet with condition

    It is not about your understanding...it is about your explanation of expected output...You always post code and ask to have it corrected instead of posting explanations of how your result was achieved...
    It's sometimes a nightmare to try and analyse another persons code...or results based on their supplied formulas...

  21. #21
    Forum Expert
    Join Date
    05-05-2015
    Location
    UK
    MS-Off Ver
    Microsoft Excel for Microsoft 365 MSO (Version 2402 Build 16.0.17328.20068) 64-bit
    Posts
    28,209

    Re: Need to add code to add an extra sheet with condition

    For future reference: consider having a macro per sheet i.e code to process that sheet only. You will probably find that much of the code can be copied/pasted with minor alterations to each macro: particularly with the type of application you are working on..

    Re JohnnyL's style (and we all have our "favoured" approach/style) of using"comprehensible" (self-documenting) variable times _ in a large macro I start to find them difficult to follow.

    In simple one-per-sheet a more "simple" naming approach could be used without losing the documentation, much of which can be provide by comments (as you have, understandably, requested).

    Good design usually leads to both simpler, and more efficient, code. Excel itself is composed to 1000s of small reusable "macros" which are used iin multiple situations.
    Last edited by JohnTopley; 04-30-2023 at 04:10 PM.

  22. #22
    Forum Contributor
    Join Date
    11-25-2021
    Location
    INDIA
    MS-Off Ver
    2007
    Posts
    2,147

    Re: Need to add code to add an extra sheet with condition

    I just read comments of previous codes and try to create something what is required by comparing codes not writing them. When I get stuck at a point I ask for help in the forum. I even post an expected result sheet and the result I have achieved till then. However, with the members support, I may not be able to explain clearly but someone or the other understands and my goal is achieved. I am sorry if my post gets you confused but you can ask and I can explain one step at a time. Only thing needed is patience and the will to understand to solve which everyone in the forum has and I am very glad about it.

  23. #23
    Forum Contributor
    Join Date
    11-25-2021
    Location
    INDIA
    MS-Off Ver
    2007
    Posts
    2,147

    Re: Need to add code to add an extra sheet with condition

    I am trying my best John Topley. Improving by the day. This query was connected to multiple workbooks so I had to post 2 sample workbooks. Whatever, you understood and solved the problem. Thank you man.
    Time to hit the sack now. Good night guys. See you soon.

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

    Re: Need to add code to add an extra sheet with condition

    ...Deleted...
    Last edited by sintek; 05-01-2023 at 08:01 AM.

  25. #25
    Forum Contributor
    Join Date
    11-25-2021
    Location
    INDIA
    MS-Off Ver
    2007
    Posts
    2,147

    Re: Need to add code to add an extra sheet with condition

    sintek. It is not that simplle. Share the workbooks with the code you tested and let me check.

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

    Re: Need to add code to add an extra sheet with condition

    Must only credit note values be changed to negative...

  27. #27
    Forum Contributor
    Join Date
    11-25-2021
    Location
    INDIA
    MS-Off Ver
    2007
    Posts
    2,147

    Re: Need to add code to add an extra sheet with condition

    I can guide you to recreate (play with) it but then again the posts may cross #40 plus. (Just joking).
    First thing is it is not a single xlsx sheet. There may be one or up to 30 sheets in different scenarios. That is why the array is created. The code will collect the data from the first xlsx sheet and join the data from the four sheets with some conditions. The condition includes that out of the 4 sheets 3 sheets may or may not contain data. Next it will do the same with the next sheet in the folder and place the result below the result of the first sheet and so on till there are as many xlsx sheets in the folder. The code will create the sheet name depending on the name of the xlsx sheet. If you understood this I will explain further if you want. It took more than a week to create this with help.

  28. #28
    Forum Contributor
    Join Date
    11-25-2021
    Location
    INDIA
    MS-Off Ver
    2007
    Posts
    2,147

    Re: Need to add code to add an extra sheet with condition

    Quote Originally Posted by sintek View Post
    Must only credit note values be changed to negative...
    Yes. The cdnr and cdnur sheets values should be in negative.

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

    Re: Need to add code to add an extra sheet with condition

    Oh okay...not to worry...I misunderstood...Wrote code only for that Invoice File extracting various columns for array based on only this sheets setup...

    Untitled.png

    If all the files had the same setup as that invoice file then adding a loop would work...

  30. #30
    Forum Contributor
    Join Date
    11-25-2021
    Location
    INDIA
    MS-Off Ver
    2007
    Posts
    2,147

    Re: Need to add code to add an extra sheet with condition

    No worries. You had fun that counts. It is really exciting to do something new each time once you know what is to be done.

  31. #31
    Forum Contributor
    Join Date
    11-25-2021
    Location
    INDIA
    MS-Off Ver
    2007
    Posts
    2,147

    Re: Need to add code to add an extra sheet with condition

    The invoice file is the copy of b2b,sez,de sheet and then the data, if any, in cdnr, cdnur and exp is copied from each selected column and pasted in the required column of b2b,sez,de sheet.

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

    Re: Need to add code to add an extra sheet with condition

    That code of yours is doing exactly the same thing all the time with every file it opens, so the data layout has to be the same...

  33. #33
    Forum Contributor
    Join Date
    11-25-2021
    Location
    INDIA
    MS-Off Ver
    2007
    Posts
    2,147

    Re: Need to add code to add an extra sheet with condition

    The time taken to combine 25 sheets in this case is
    A_Combine Data From EInvoices completed in 8.9951171875 seconds.
    A2 Combined E Invoices sheets in 0.6220703125 seconds.
    What more can I expect.

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

    Re: Need to add code to add an extra sheet with condition

    All good...

+ 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. [SOLVED] Code not copying to extra sheet
    By kris01 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 11-19-2021, 12:30 PM
  2. [SOLVED] Add extra value on if condition
    By bluepomme in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 07-10-2019, 12:50 AM
  3. how to attached extra condition in formula based sheet
    By anindya.zen in forum Excel Formulas & Functions
    Replies: 9
    Last Post: 05-17-2017, 12:45 AM
  4. [SOLVED] Extra space or spaces in Text in Forum Post. BB Code for extra space ?
    By Doc.AElstein in forum The Water Cooler
    Replies: 21
    Last Post: 03-02-2016, 02:59 PM
  5. [SOLVED] VBA code required to insert extra/New sheets with existing sheet data
    By mchilapur in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 02-22-2015, 01:52 AM
  6. Help to add an extra condition in IF formula
    By KELLIS in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 10-14-2013, 01:57 PM
  7. Inserting extra row based on condition
    By nobleprince in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 09-25-2010, 08:40 PM

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