+ Reply to Thread
Results 1 to 36 of 36

Code to create a sheet and get selected data from the source sheet

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

    Code to create a sheet and get selected data from the source sheet

    Hello code experts
    I had posted this query in this forum but I have not received a single reply.
    https://www.mrexcel.com/board/thread...sheet.1218091/
    There is only one sheet in the workbook B2B with Code button sheet. The Not imported is the expected result of the code which is to be created. When I press the button, a new sheet is created "Portal". I need your help to get the "Not Imported" sheet with the help of a code. The "Not Imported" sheet which is manually created to show the expected result. I should be able to get the result with a single button with both the sheets created. I have a rough idea how to write the code but as I am not a coder I can explain my requirement.
    Create a copy of Portal In the Random Access Memory and with the help of below steps create the Not imported sheet. As some of the rows are combined in the portal sheet by the code, copy the rows from B2B to Not imported. The Portal sheet is only for reference to get the 0 Rates and rows with Yes / Y in column H.
    1. In the portal sheet, If the value of CGST, SGST and IGST are 0 (Match Entire cell contents), then shift those rows to "Not Imported" sheet row 7 onwards as displayed in B2B. Please note: not from portal but from B2B
    2. In some rows where the value of Invoice Value and Taxable are same shift those rows to "Not Imported" sheet as displayed in B2B. Please note: not from portal but from B2B
    3. Shift the rows with Yes and Y in column H to "Not Imported" sheet as displayed in B2B. Please note: not from portal but from B2B.

    This new project is created with the help of comments of previous applications. I would really appreaciate if comments are written at the end of each line of code. It will really help me to edit and create future applications.
    Thanking you in advance.
    Attached Files Attached Files
    Last edited by RAJESH SHAH; 10-22-2022 at 08:18 AM. Reason: #Solved by John Topley

  2. #2
    Forum Expert Logit's Avatar
    Join Date
    12-23-2012
    Location
    North Carolina
    MS-Off Ver
    Excel 2019 Professional Plus - 2007 Enterprise
    Posts
    7,015

    Re: Code to create a sheet and get selected data from the source sheet

    Are you talking about columns L, M, N for the different taxes ?

    Are you speaking of columns F & J ?

    And Column H you have identified.


    Is all of the above correct ?

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

    Re: Code to create a sheet and get selected data from the source sheet

    Taxes columns are K L M and N only
    F is the invoice value as mentioned and J is the taxable value
    You are right. Column H is to identify Yes / Y which are to be shifted to Not Imported sheet.
    Also column I is 0 (match entire cell contents) then shift those to Not imported sheet.
    Where the values in column F and J are the same in a row then shift them too to Not imported sheet.
    Last edited by RAJESH SHAH; 10-03-2022 at 01:58 AM.

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

    Re: Code to create a sheet and get selected data from the source sheet

    Logit, are you still trying to create the new sheet and get the required data.? If you think this is tough then you should see the next query i am going to post. I am not sure whether it is possible or not.
    Last edited by RAJESH SHAH; 10-03-2022 at 02:01 AM.

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

    Re: Code to create a sheet and get selected data from the source sheet

    This is to let everyone know that the query is still unsolved. I have had no response from the other forum too where I had shared this query. Hopefully, someone can understand and provide a solution🤞.

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

    Re: Code to create a sheet and get selected data from the source sheet

    Shared the query once again elsewhere.

    https://www.facebook.com/groups/393224307706029/

  7. #7
    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,240

    Re: Code to create a sheet and get selected data from the source sheet

    Please Login or Register  to view this content.
    Attached Files Attached Files
    If that takes care of your original question, please select Thread Tools from the menu link above and mark this thread as SOLVED.

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

    Re: Code to create a sheet and get selected data from the source sheet

    Thank you John Topley. The code is giving the perfect result. Thank you very much for the comments too.
    There are 2 things to be corrected if you can please help me correct them and complete this. As this is just a stage of the project I am working on I will have just 2 sheets in the project. All the other 8 sheets are created by the code.
    One is the Not Imported sheet is not in the workbook. It is to be created by the code and secondly I need the same headings in Not Imported sheet as the headings are connected to other sheets in the workbook.

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

    Re: Code to create a sheet and get selected data from the source sheet

    The second time I tested the code it is not displaying anything. Maybe this line is deleting the data
    Please Login or Register  to view this content.
    I will check back again tomorrow and let you know. Time to hit the sack now. Good Night.

  10. #10
    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,240

    Re: Code to create a sheet and get selected data from the source sheet

    You had a recent post regrding creating a new sheet and adding headings so you should be able to incorporate this into your current code.

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

    Re: Code to create a sheet and get selected data from the source sheet

    You got confused due to that. That is a different sheet in the same workbook. This is different. As I told you there are around 8 different sheets to be created in different formats. The sheet you are talking about had the headings in the first row.

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

    Re: Code to create a sheet and get selected data from the source sheet

    The headings in this sheet are merged in multiple cells. So, i will not be able to incorporate that in this code.

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

    Re: Code to create a sheet and get selected data from the source sheet

    It is very simple. With the help of a code just create a copy of the B2B sheet, rename the sheet as Not Imported, Delete the data from row 7 tilll end and then the code will do the rest. The only problem is I don't have enough knowledge of coding to do that.

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

    Re: Code to create a sheet and get selected data from the source sheet

    I think I found the reason for data not displaying in the Not imported sheet. When I deleted Portal sheet and re created it with the button 1, the portal sheet is created but when I press the Run Not imported button it doesn't display anything, just a blank 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,240

    Re: Code to create a sheet and get selected data from the source sheet

    You "corrupt" yiour data by adding"-Total" to Invoice Numbers in Portal so they NEVER match those in B2B: not very smart!!!

    Sorry ... but I cleared the data while tesitng.

    Change the Ortal extract.

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

    Re: Code to create a sheet and get selected data from the source sheet

    To add The -total in the portal sheet s a necessity, but that column is no where connected in the above 3 conditions. I hope you are not confused with invoice value to Invoice number..
    Please note: In the expected sheet, there is no -Total as the data is copied from the B2B sheet. I have entered by mistake in that sheet.
    Last edited by RAJESH SHAH; 10-04-2022 at 11:49 PM.

  17. #17
    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,240

    Re: Code to create a sheet and get selected data from the source sheet

    Please Login or Register  to view this content.
    I changed macro to check Party No rather than Invoice to select all B2B records to be included.

    And why are you re-creating the "Not Imported" sheet: if headings change (?!!) then simply clear "Not Included" then copy headings from "B2B" to "Not Included".

    Similar for other sheets.

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

    Re: Code to create a sheet and get selected data from the source sheet

    What do you mean by Party No. ? The headings of the B2B will be always the same. When I run the code all the created sheets will be hidden. Only the final result will generate 2 xml files and will be saved on the desktop. So, the final user will never know what is happening in the hidden sheets. It is for security purpose to hide the sheets as the user by mistake, doesn't tamper with the formulas or codes in the hidden sheets as well as the code.
    As for the new code it is displaying a blank sheet once again.

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

    Re: Code to create a sheet and get selected data from the source sheet

    Sorry I didn't replace the old with the new code. It is working but it is not showing the last 2 rows where Invoice value and Taxable value are the same. (condition 2).
    Last edited by RAJESH SHAH; 10-05-2022 at 06:40 AM.

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

    Re: Code to create a sheet and get selected data from the source sheet

    For your reference, In the B2B sheet I have colored the cells yellow which should show in the Not imported sheet. Please Check the new file I shared in post #18.

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

    Re: Code to create a sheet and get selected data from the source sheet

    John Topley. The whole query is solved. Thank you very much man.

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

    Re: Code to create a sheet and get selected data from the source sheet

    John Topley. I am facing an error when I change the data in the B2B sheet. Can you please help me to correct the code and avoid the error.? When I press the convert data to poral it is working right. It is creating a sheet Portal and converting the data. The not imported sheet is already created with the headings, but when I press copy to not imported sheet button, I am getting a run time error 9 and the cells too are empty.

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

    Re: Code to create a sheet and get selected data from the source sheet

    The B2B sheet is different in this case. It has multiple rows of each transaction with a blank row between each transaction. The code you wrote was for transactions with single row of data. So, I will need your help once again to edit the code accordingly.

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

    Re: Code to create a sheet and get selected data from the source sheet

    John Topley. I have re constructed the whole idea to get the data from B2B to 2A and Not imported sheets. I have tried to make it as simple as possible for you to understand. I hope it would be very easy for you to write the code once you have understood it.
    In the workbook there are 3 worksheets only B2B, 2A and Not imported. After I open the workbook, I have to paste the new B2B data in the B2B worksheet. The 2A and Not imported sheet will be blank when opened. I have explained the details in brief how I manually separate the B2B data and get the data in the 2A and Not imported sheet. The code in the workbook is of a previous query which I was not able to edit. Maybe it will help you to understand better.
    The other 2 sheets in the workbook are to show how the expected result will be.
    Please have a peek at this and if possible include the code for conditional formatting of B2B within the code.
    Thank you in advance.
    Last edited by RAJESH SHAH; 10-17-2022 at 11:54 AM.

  25. #25
    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,240

    Re: Code to create a sheet and get selected data from the source sheet

    Please Login or Register  to view this content.
    Last edited by JohnTopley; 10-17-2022 at 05:44 AM.

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

    Re: Code to create a sheet and get selected data from the source sheet

    Wow! That was super fast man. I didn't expect it so soon. Will check and revert back.

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

    Re: Code to create a sheet and get selected data from the source sheet

    This is just perfect man. Phew! After 10 days of changing the ideas multiple times, finally we got this right. Thank you very much John Topley. You just solved the most complicated part which was pending since long. Thanks once again. See you soon.
    I am not able to add reputation to your latest post. Maybe I can give reputation only once per post.
    Last edited by RAJESH SHAH; 10-17-2022 at 08:19 AM. Reason: #Solved by John Topley

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

    Re: Code to create a sheet and get selected data from the source sheet

    I am confused why I am not getting the amounts in columns H to AG in some of the rows. I noticed that where the invoice number contains text, it is giving the correct results. But if it is numbers then the formulas in column H to AG are not displaying the correct amount instead it is displaying 0. Can anyone please help me to find whether the fault is in the formulas or code and help me to correct it.?
    Attached Files Attached Files

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

    Re: Code to create a sheet and get selected data from the source sheet

    The B2B sheet contains the rows of the Not imported sheet too. Hence the 2A Edited is displaying the rows of the Not imported sheet which are not in 2A. So, I think I have found the mistake. Hopefully I will try to sort it out.

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

    Re: Code to create a sheet and get selected data from the source sheet

    All the problems are solved but one.
    Last edited by RAJESH SHAH; 10-22-2022 at 08:19 AM.

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

    Re: Code to create a sheet and get selected data from the source sheet

    John Topley. Your code is perfect man. It is just that I received a new data yesterday in which some invoice value rows were not matching and having wrong total. (The total of columns J k L and M should be equal to column F with a nominal difference of +1 or -1).
    I want your help to add one more condition in the code. Match the amount of Column F with the sum of columns J K L and M and if the difference is more than +1 or -1 then shift those columns to Not imported sheet. In this case the rows 275, 276, 278, 279, 281 and 282 to be shifted to Not Imported as difference is more than 1. The rows with the wrong total can be anywhere in the sheet. This is just a sample sheet and I have entered them in the end of the sheet for your reference.
    Attached Files Attached Files
    Last edited by RAJESH SHAH; 10-22-2022 at 02:10 PM.

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

    Re: Code to create a sheet and get selected data from the source sheet

    John Topley, I hope you are reading this. Issue 2. I have one issue in getting the 2A data. The invoice numbers are converted into numbers by the code in some cases where the invoice number is like in the yellow cells in the below image. Can you please edit your code to get the data as text.? Issue 1. in post #31
    Attachment 802304
    I got the issue 2 corrected. I formatted the column of invoice number as general in the 2A data sheet and I got the correct values.
    Only one issue is pending. Not an issue exactly, I wanted to add one more condition with the 3 conditions you have already mentioned in the code.
    Last edited by RAJESH SHAH; 10-26-2022 at 08:25 AM.

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

    Re: Code to create a sheet and get selected data from the source sheet

    I have posted the same query on Mr.Excel to solve the problem.

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

    Re: Code to create a sheet and get selected data from the source sheet

    I am not getting any response from no one. John Topley I will share the code which needs to be edited and corrected. While I was transferring the data from sheet B2B to 2A, I came across one data where the invoice number which is printed as a date in the result. I just want the invoice number in text format in the 2A sheet. This is the code you shared. I think it will be easier for you to edit the code at just one line I think.
    Please Login or Register  to view this content.

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

    Re: Code to create a sheet and get selected data from the source sheet

    I am sharing the images of both, the original and the result. I hope you will correct the code to get the correct value.🤞
    Attachment 803003
    Attachment 803004

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

    Re: Code to create a sheet and get selected data from the source sheet

    I am not receiving any replies for this post. Is this post closed ? Can I continue in the same post or should I post a new one ?
    I added one line in the code and got the value of the date like invoice number correct but got errors in non text invoice numbers. I hope someone will be able to solve this issue.
    Line added in the end of the code as:
    Please Login or Register  to view this content.
    Last edited by RAJESH SHAH; 11-01-2022 at 03:01 AM.

+ 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] Macro to create multiple sheet (selected variable) from master sheet
    By sarat47 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 11-17-2020, 12:30 AM
  2. [SOLVED] Copy Data from "Source" Sheet to "Target" Sheet (Code need help thanks)
    By mankit87 in forum Excel Programming / VBA / Macros
    Replies: 19
    Last Post: 07-17-2019, 11:45 PM
  3. WBs to 1 Sheet code doesn't allow to choose certain data range from source workbooks
    By Mahmoud.1st in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 03-22-2016, 07:12 AM
  4. Replies: 0
    Last Post: 07-21-2015, 10:26 PM
  5. Create New Sheet From Selected Data
    By UnreadSix in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 02-27-2014, 01:12 PM
  6. VBA code for coping selected data to another sheet based on a criteria
    By BJ5352 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 07-14-2010, 02:16 AM
  7. How to create a summary sheet that returns user selected data
    By nalmarri in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 12-22-2008, 03:53 AM

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