+ Reply to Thread
Results 1 to 20 of 20

VBA - Copy data into new worksheet

  1. #1
    Registered User
    Join Date
    06-03-2018
    Location
    Thailand
    MS-Off Ver
    2016
    Posts
    30

    VBA - Copy data into new worksheet

    Hi,

    In OR sheet, I would like to copy column D, E, F & G to Report sheet if C equal to "DZ". Then by using column G in Report, find info from Invoice sheet for column H to J in Report.

    In Report
    Column H = amount for type AO & A8 (85% of tax base amount) in Invoice sheet
    Column I = amount for type A1 & A8 (15% of tax base amount) in Invoice sheet

    Please take a look at the expected result as attached. Thank you in advance!
    Attached Files Attached Files

  2. #2
    Forum Expert Keebellah's Avatar
    Join Date
    01-12-2014
    Location
    The Netherlands
    MS-Off Ver
    Office 2021 (Windows)
    Posts
    7,906

    Re: VBA - Copy data into new worksheet

    You could at least be a little more specific about where goes what.
    You make it difficult for others to first search what goes where. YOU know the values but others don't,
    I assume that the references in the thumbnail are correct?
    Attached Images Attached Images
    ---
    Hans
    "IT" Always crosses your path!
    May the (vba) code be with you... if it isn't; start debugging!
    If you like my answer, Click the * below to say thank-you

  3. #3
    Registered User
    Join Date
    06-03-2018
    Location
    Thailand
    MS-Off Ver
    2016
    Posts
    30

    Re: VBA - Copy data into new worksheet

    Sorry, attached with the updated formula.
    Attached Images Attached Images
    Attached Files Attached Files

  4. #4
    Forum Expert Keebellah's Avatar
    Join Date
    01-12-2014
    Location
    The Netherlands
    MS-Off Ver
    Office 2021 (Windows)
    Posts
    7,906

    Re: VBA - Copy data into new worksheet

    Clear, will see if I can help you

  5. #5
    Forum Expert Keebellah's Avatar
    Join Date
    01-12-2014
    Location
    The Netherlands
    MS-Off Ver
    Office 2021 (Windows)
    Posts
    7,906

    Re: VBA - Copy data into new worksheet

    What if there are more than one with DZ, do you want to append to an existing reports or do want to clear the report sheet with every query?

  6. #6
    Forum Expert Keebellah's Avatar
    Join Date
    01-12-2014
    Location
    The Netherlands
    MS-Off Ver
    Office 2021 (Windows)
    Posts
    7,906

    Re: VBA - Copy data into new worksheet

    Doesn't make sense check your file, I think you mean invoice A and invoice C
    Attached Images Attached Images

  7. #7
    Forum Expert Keebellah's Avatar
    Join Date
    01-12-2014
    Location
    The Netherlands
    MS-Off Ver
    Office 2021 (Windows)
    Posts
    7,906

    Re: VBA - Copy data into new worksheet

    I think this whole file doesn't make sense at all so I hope you can explain it before we put precious time into it.
    You say you look at the OR contents in Column C for a cell with the value 'DZ', if found the data is copied to the columns you have mentioned in the Reprot worksheet, so far that is clear.
    After that you find data in the Invoice sheet but what does it refer to?
    There is no relationship between the OR and the Invoice sheet to know/make sure what data to fetch.

    Furthermore I was wondering why your file was so big with so little data (at first sight) but that's because you've left a whole lot of data in column G of the Report sheet starting at row 7000 125403 and then again some more starting in Column A-D at row 125404 down to row 126228 in column D
    Sloppy !!!
    But first, explain more. Not going to work with this.

  8. #8
    Registered User
    Join Date
    06-03-2018
    Location
    Thailand
    MS-Off Ver
    2016
    Posts
    30

    Re: VBA - Copy data into new worksheet

    Sorry, I try to explain in details.

    With the same clearing doc in OR G,
    - copy from D to G with document type DZ to Report A to D
    - copy from D to F with document type T2 to Report F & G

    Then, make reference to Report G:
    - if in Invoice D (Tx is AO), the tax base amount in E will flow to Report H
    - if in Invoice D (Tx is A1), the tax base amount in E will flow to Report I
    - if in Invoice D (Tx is A8), 85% the tax base amount in E will flow to Report H and 15% to I
    - Invoice F to Report J

    Hope it make sense. Many thanks!

  9. #9
    Forum Expert Keebellah's Avatar
    Join Date
    01-12-2014
    Location
    The Netherlands
    MS-Off Ver
    Office 2021 (Windows)
    Posts
    7,906

    Re: VBA - Copy data into new worksheet

    Yes, that I understood but I see no relationship between the OR and the Invoice worksheet to know which one to select.
    THAT is what you nee to explain. How do you know which row in Invoice to select based on the data from the OR worksheet?

    The values in Invoice Column C are not found in OR column A, B or E

    Guessing is not an option so either the data you have in the sample workbook is incomplete or ....

  10. #10
    Registered User
    Join Date
    06-03-2018
    Location
    Thailand
    MS-Off Ver
    2016
    Posts
    30

    Re: VBA - Copy data into new worksheet

    In column E OR worksheet, every OR number will follow by the invoice number to show the receipt amount and for which invoices were paid. These invoice number is the same as column C in Invoice worksheet. These are all the data that I have and I want to populate it to the Report worksheet. Basically, I want to show the OR details paid for which invoices and amount.

  11. #11
    Forum Expert Keebellah's Avatar
    Join Date
    01-12-2014
    Location
    The Netherlands
    MS-Off Ver
    Office 2021 (Windows)
    Posts
    7,906

    Re: VBA - Copy data into new worksheet

    Then WHY the DZ selection? I do not see any clear relation to that
    I like to understand things and see no relation between the value in OR E to what I see in Invoice C
    Does it mean that you just want to copy adat and nothing related? Except the document type?

  12. #12
    Registered User
    Join Date
    06-03-2018
    Location
    Thailand
    MS-Off Ver
    2016
    Posts
    30

    Re: VBA - Copy data into new worksheet

    I want to copy from column E in OR with the same clearing document to respective columns in Report worksheet i.e. column B,D,F & G. The amount in Report worksheet column H to J is from Invoice worksheet.

  13. #13
    Forum Expert Keebellah's Avatar
    Join Date
    01-12-2014
    Location
    The Netherlands
    MS-Off Ver
    Office 2021 (Windows)
    Posts
    7,906

    Re: VBA - Copy data into new worksheet

    I see wher your explanation goes wrong:
    In the first post you said the following: (I added Ste 1 and Step 2 to try an understand)
    Step 1: In OR sheet, I would like to copy column D, E, F & G to Report sheet if C equal to "DZ".

    Step 2: Then by using column G in Report, find info from Invoice sheet for column H to J in Report.*In Report*Column H = amount for type AO & A8 (85% of tax base amount) in Invoice sheet Column I = amount for type A1 & A8 (15% of tax base amount) in Invoice sheet
    Please take a look at the expected result as attached.
    Thank you in advance!
    If you read step 2 then you see what I mean you start explaining that you want using Column G in Report find the values but Column G is empty after Step 1
    You meant in Column G OR find the corresponding in Invoice Column C THEN it starts making sense.

    So you see, if the explanation is correct it's easier to understand and not expect others to assume they understand what you're asking.
    But Okay, it's clear. will work on it.

    How is you Macro knowledge (VBA?)

  14. #14
    Registered User
    Join Date
    06-03-2018
    Location
    Thailand
    MS-Off Ver
    2016
    Posts
    30

    Re: VBA - Copy data into new worksheet

    I have very limited knowledge about VBA. If you could explain how it works, I would appreciate it.

    Thank you for your patience

  15. #15
    Forum Expert Keebellah's Avatar
    Join Date
    01-12-2014
    Location
    The Netherlands
    MS-Off Ver
    Office 2021 (Windows)
    Posts
    7,906

    Re: VBA - Copy data into new worksheet

    Will do my best (explaining), will work on it later today

  16. #16
    Forum Expert Keebellah's Avatar
    Join Date
    01-12-2014
    Location
    The Netherlands
    MS-Off Ver
    Office 2021 (Windows)
    Posts
    7,906

    Re: VBA - Copy data into new worksheet

    Okay, this is what I have come up with.
    I added quite a few comments in the VBA project for you to read and grasp the idea, hope it helps you.
    Coding VBA is possible in many ways as long as the syntax is respected. How it's approached that's entirely personal.
    VBA and code is limited only by the person's fantasy
    Press the smiley in the OR sheet to trigger the macro and generate the report.
    The worksheet Report (2) is your original sample result.
    Attached Files Attached Files

  17. #17
    Forum Expert Keebellah's Avatar
    Join Date
    01-12-2014
    Location
    The Netherlands
    MS-Off Ver
    Office 2021 (Windows)
    Posts
    7,906

    Re: VBA - Copy data into new worksheet

    There is quite some inconsistency in YOUR sample (see attachment 'Explanation')
    and a modified version of my last solution

    I suggest you look at the explanation first and explain the inconsistency
    Attached Files Attached Files

  18. #18
    Registered User
    Join Date
    06-03-2018
    Location
    Thailand
    MS-Off Ver
    2016
    Posts
    30

    Re: VBA - Copy data into new worksheet

    Hi Keebellah,

    You are right, the clearing doc should be the same. Thank you for the solutions and explanation but I still do not know the difference between 1st and the 2nd version . Is there any way to speed up the code?

    May I request the following in Report:

    - header start from row 4
    - font & size: Arial with size 8
    - date: dd/mm/yyyy
    - amount from "H" onwards to remove negative, just to show positive figures
    - to have bottom border after each clearing doc as per my attachment

    I also want to change sample result as attached as there are changes to the data source in OR. Please take a look when you have time. Thank you very much!
    Attached Files Attached Files

  19. #19
    Forum Expert Keebellah's Avatar
    Join Date
    01-12-2014
    Location
    The Netherlands
    MS-Off Ver
    Office 2021 (Windows)
    Posts
    7,906

    Re: VBA - Copy data into new worksheet

    I have given you the help you requested, and yes the modifications can be doen.
    I think that if you try and read the code as you would text to see what it does (it's explained in a way in the comments) you could come up with the the solution too.
    The difference (if you read the two versions) you will see that it checks if there is already a value in the same cell, it adds it up.
    If you want the numbers to be positive, ten all you need to do is make the value ABS (absolute)
    I'm off you a long weekend.
    Hope you can figure it out, it's good to learn how to code so you do not stay dependent of others

  20. #20
    Forum Expert Keebellah's Avatar
    Join Date
    01-12-2014
    Location
    The Netherlands
    MS-Off Ver
    Office 2021 (Windows)
    Posts
    7,906

    Re: VBA - Copy data into new worksheet

    And don't forget, that you altered the report sheet, added an empty column, so well.
    You asked, you got an answer.
    If you then decide it all has to be modified then, well, my advice is to get someone with some vba knowledge, give him my code (there are of course many other ways others would do it) and build on from that.
    Like I said, after the weekdn and if I have time I'll see if understand the changes you want

+ 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. Replies: 13
    Last Post: 10-05-2015, 08:59 AM
  2. Macro to copy data from multiple worksheet cells in to a single Master worksheet
    By thunt13 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 05-08-2015, 03:24 PM
  3. Replies: 3
    Last Post: 05-26-2014, 02:21 AM
  4. [SOLVED] Copy data from a worksheet and paste to worksheet with a similar worksheet name
    By maacmaac in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 10-21-2012, 04:02 AM
  5. Copy data from a worksheet and paste to worksheet with a similar worksheet name
    By maacmaac in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 10-21-2012, 02:49 AM
  6. Replies: 8
    Last Post: 04-20-2011, 09:45 AM
  7. Replies: 4
    Last Post: 02-25-2009, 03:16 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