+ Reply to Thread
Results 1 to 14 of 14

CODE REVIEW: copy paste + look up

  1. #1
    Registered User
    Join Date
    07-04-2017
    Location
    Belgium
    MS-Off Ver
    365 ProPlus
    Posts
    81

    CODE REVIEW: copy paste + look up

    Hey guys,

    This code works as intended, but I am wondering if someone could give me some advice on how to code faster and cleaner.

    Purpose: verifying if our purchase orders were sent out.
    Method: I summarize 3 worksheets with data in the worksheet 'Overview'.
    I first create the headers, then copy paste 5 columns and then fill in 2 more columns with data using look ups.

    Please Login or Register  to view this content.
    *Uploaded v4 with some tweaks and first feedback.
    Attached Files Attached Files
    Last edited by dunnobe; 08-14-2019 at 09:52 AM.

  2. #2
    Registered User
    Join Date
    07-04-2017
    Location
    Belgium
    MS-Off Ver
    365 ProPlus
    Posts
    81

    Re: CODE REVIEW: copy paste + look up

    Some additional information. I have the for each/do until loop from another guy on the forum who gave me some advice.
    I basically recycled it and adapted it to my needs.

    In the first part, I look up a PO-number (r.value) in a worksheet that has this PO-number multiple times and check if one of these PO-numbers has status = "1".
    In the second part, I count how many times r.value is in a worksheet and count how many of these are deleted ("L"). -> If the # lines = # deleted lines, the entire order has been deleted (= varResult).

  3. #3
    Forum Guru Sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2019 | 2021
    Posts
    14,958

    Re: CODE REVIEW: copy paste + look up

    I am very certain that someone will be able to simplify and speed up the process...However, a sample upload file depicting your exact setup will be required...
    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 [★ Add Reputation] to left of post window...
    Also....Add a comment if you like!!!!
    And remember...Mark Thread as Solved...
    Excel Forum Rocks!!!

  4. #4
    Registered User
    Join Date
    07-04-2017
    Location
    Belgium
    MS-Off Ver
    365 ProPlus
    Posts
    81

    Re: CODE REVIEW: copy paste + look up

    Cool, I will after my break!

    I might be doing some unnecessary looping in the last part of the code. I have to look up the value only 1 time and count # lines and # deleted lines and then find the next r.value.

    This seems to give the same result and cuts down the running time of the code in half!

    Please Login or Register  to view this content.

  5. #5
    Valued Forum Contributor
    Join Date
    06-27-2010
    Location
    sYRIA
    MS-Off Ver
    Excel 2013
    Posts
    669

    Re: CODE REVIEW: copy paste + look up

    Hi dunnobe
    There is another loop not needed in fact
    for the Headers try some thing like:
    Please Login or Register  to view this content.
    Last edited by mohadin; 08-14-2019 at 07:25 AM.

  6. #6
    Registered User
    Join Date
    07-04-2017
    Location
    Belgium
    MS-Off Ver
    365 ProPlus
    Posts
    81

    Re: CODE REVIEW: copy paste + look up

    @mohadin:

    I guess it has to be like this as the first value of an array is 0 and thus your code would be ... , Cells(1, 0) = headers

    Please Login or Register  to view this content.
    Last edited by dunnobe; 08-14-2019 at 07:41 AM.

  7. #7
    Forum Guru Sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2019 | 2021
    Posts
    14,958

    Re: CODE REVIEW: copy paste + look up

    Please Login or Register  to view this content.

  8. #8
    Forum Guru Sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2019 | 2021
    Posts
    14,958

    Re: CODE REVIEW: copy paste + look up

    '! Thread not allowing me to edit post...............

    Please Login or Register  to view this content.

  9. #9
    Registered User
    Join Date
    07-04-2017
    Location
    Belgium
    MS-Off Ver
    365 ProPlus
    Posts
    81

    Re: CODE REVIEW: copy paste + look up

    Hey sintek,

    Thanks.
    The result is a bit off, but it's interesting to see how you do things diferrently than me .
    I can learn from it.

    Br,

    dunnobe

  10. #10
    Forum Guru Sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2019 | 2021
    Posts
    14,958

    Re: CODE REVIEW: copy paste + look up

    The result is a bit off
    Can you clarify by an upload with expected result...Your initial upload which had the results has been replaced with another file...
    Last edited by Sintek; 08-19-2019 at 05:55 AM.

  11. #11
    Registered User
    Join Date
    07-04-2017
    Location
    Belgium
    MS-Off Ver
    365 ProPlus
    Posts
    81

    Re: CODE REVIEW: copy paste + look up

    Hey sintek,

    There might be a mistake in the latter part of the code:

    Please Login or Register  to view this content.
    A value could occur multiple times in worksheet 'NAST'.
    F.e. Orders 4522256126, 4522256189, 4522256257 occur multiple times in that table, with both a corresponding value 0 and 1. Considering value 1 exists for these numbers, it should return "OK".
    Does your code only returns a result for the first time it finds the value?
    Attached Files Attached Files
    Last edited by dunnobe; 08-19-2019 at 09:27 AM.

  12. #12
    Forum Guru Sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2019 | 2021
    Posts
    14,958

    Re: CODE REVIEW: copy paste + look up

    Oh, i see what you mean...So if any of the rows containing that number has a 1 in Column U then it must be ok...
    Declare cnt as long and then this should work...
    Please Login or Register  to view this content.

  13. #13
    Registered User
    Join Date
    07-04-2017
    Location
    Belgium
    MS-Off Ver
    365 ProPlus
    Posts
    81

    Re: CODE REVIEW: copy paste + look up

    Thank man! +1 reputation

    The result seems to be the same as my macro for this small amount of data, but faster.

    I'll have a look later on to see what I can learn from your code.

  14. #14
    Forum Guru Sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2019 | 2021
    Posts
    14,958

    Re: CODE REVIEW: copy paste + look up

    Pleasure...Tx for rep +

+ 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. MACRO: seek, copy and paste only the last review of a drawing
    By Dampyr2345 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 01-25-2018, 10:26 AM
  2. copy certain cells from all worksheets to one sheet. Need review of my VBA code.
    By ChrisLo87 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 02-21-2017, 11:44 AM
  3. Review row criteria and paste on incremental row on another sheet
    By jdannis79 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 03-09-2016, 12:26 PM
  4. Code bloat - Please review my code for improvement
    By AnnieBrownTX in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 02-05-2016, 11:50 AM
  5. [SOLVED] Need to review this code
    By kiranpat in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 08-29-2014, 05:57 AM
  6. [SOLVED] Code Review
    By Eric in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 02-17-2006, 03:00 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