Closed Thread
Results 1 to 31 of 31

Modify This Code for WorkBook Loop

  1. #1
    Registered User
    Join Date
    05-20-2008
    Posts
    20

    Modify This Code for WorkBook Loop

    As you can see the code below, everything is the same, except
    template(x).xls
    where x is 1,2,3 and so on.

    Can someone help me to modify this code so it'll look through every template(x).xls workbook in the same folder?

    as an additonal question, when I use the below below on a new worksheet, it starts at line 2, is there a way to start at line1 or line 5?

    Please Login or Register  to view this content.

  2. #2
    Forum Expert
    Join Date
    01-15-2007
    Location
    Brisbane, Australia
    MS-Off Ver
    2007
    Posts
    6,591
    Hi

    1) Didn't test this but here goes.

    Please Login or Register  to view this content.
    Note: this copies the data from columns A:D. In your code, you do this for template1.xls, but then only copy columns A:C, yet output the last quantity from the first file. Is that correct???

    2) I've commented out some code that should start the output in row 5 (or some nominated row above 2).

    3) If you want to start at row 1, the easiest way I've found is to have a boolean variable (say fone) that is set to true. Then test on that variable. If it is true, then (a) use 1 as the output row (b) turn it to false (c) use the normal offset approach for the rest of the output.

    HTH

    rylo

  3. #3
    Registered User
    Join Date
    05-20-2008
    Posts
    20
    Thank you for prompt reply!
    forgot to mention something...

    it is template(*).xls
    rather than template*.xls

    so I just modify: filess = Dir("template*.xls")
    to Dir("template(*).xls")
    ?

    oh, the reason I did the compliated looping over copy and paste is because the first 4 rows I do not want to copy.

    hmm, your copy and paste jsut overlaps each other.
    in this case I got 3 sheets template1.xls, template2.xls, template3.xls
    template2 overwrites template1, template 3 overwrites template2
    result: template3 only.
    Last edited by Pukka83; 06-20-2008 at 12:32 AM.

  4. #4
    Forum Expert
    Join Date
    01-15-2007
    Location
    Brisbane, Australia
    MS-Off Ver
    2007
    Posts
    6,591
    Hi

    I put the attached file and 3 sample workbooks (template(1).xls, template(2).xls and template(3).xls) in the same directory.

    Opened up the attached file and ran the code. All the data was output correctly.

    Can you try, and if you are still getting problems, attach the 3 template workbooks you are using.

    rylo
    Attached Files Attached Files

  5. #5
    Registered User
    Join Date
    05-20-2008
    Posts
    20
    Hi sorry the the trouble. It does display, but has empty spaces inbetween and abit incorrect. It's not suppose to show the headers.

    attached is the files.
    Attached Files Attached Files

  6. #6
    Forum Expert
    Join Date
    01-15-2007
    Location
    Brisbane, Australia
    MS-Off Ver
    2007
    Posts
    6,591
    Hi

    OK try this. I've also changed the output to show the values rather than the formulas.

    Please Login or Register  to view this content.
    rylo

  7. #7
    Registered User
    Join Date
    05-20-2008
    Posts
    20
    Hi, thanks for your reply. For some odd reason it still display funnigly. Anyway I modified it to make it work somehow.

    I managed to do the combine the row if column B matches. However column D(quantity, number value), i want the quantity to add-up if column B matches. Any idea how do I modify the code below to do that?

    for example:
    TDG-**002 Tuna Cheese Pizza Bar (KG) KG 30
    TDG-**002 Tuna Cheese Pizza Bar (MG) MG 30
    TDG-**002 Tuna Cheese Pizza Bar (KG) KG 30

    will combine to become
    TDG-**002 Tuna Cheese Pizza Bar (KG) KG 60 <<<< combined
    TDG-**002 Tuna Cheese Pizza Bar (MG) MG 30 <<<< left untouched


    Taken from the code below:
    Please Login or Register  to view this content.
    Please Login or Register  to view this content.
    Attached Files Attached Files
    Last edited by Pukka83; 06-20-2008 at 03:23 AM.

  8. #8
    Registered User
    Join Date
    05-20-2008
    Posts
    20
    *hadouken*

  9. #9
    Registered User
    Join Date
    05-20-2008
    Posts
    20
    *hadouken*

  10. #10
    Forum Expert
    Join Date
    01-15-2007
    Location
    Brisbane, Australia
    MS-Off Ver
    2007
    Posts
    6,591
    Hi

    Sorry but had no idea what *hadouken* meant. I'm presuming it was a BUMP.

    Try this revised approach.

    Please Login or Register  to view this content.
    rylo

  11. #11
    Registered User
    Join Date
    05-20-2008
    Posts
    20
    thank you very much! I'll try it out now

    well nowadays you can wiki everything:
    http://en.wikipedia.org/wiki/Hadouken


    it is a fireball move(signature move) done by the fighters ryu, ken in street fighter

  12. #12
    Registered User
    Join Date
    05-20-2008
    Posts
    20
    tried your code, it says out of range...

    anyway i found that the below code works, myabe I just need it to combine the quantity values before it deletes the duplicates. any idea?


    Please Login or Register  to view this content.

  13. #13
    Registered User
    Join Date
    05-20-2008
    Posts
    20
    *hadouken*

  14. #14
    Forum Expert
    Join Date
    01-15-2007
    Location
    Brisbane, Australia
    MS-Off Ver
    2007
    Posts
    6,591
    Hi

    Where is it giving the out of range error?

    rylo

  15. #15
    Registered User
    Join Date
    05-20-2008
    Posts
    20
    hi, overhere:

    Range("J2").AutoFill Destination:=Range("J2:J" & Cells(Rows.Count, "G").End(xlUp).Row)

  16. #16
    Forum Expert
    Join Date
    01-15-2007
    Location
    Brisbane, Australia
    MS-Off Ver
    2007
    Posts
    6,591
    Hi

    Is there any data being imported from your source files? Is there actually any data copied across to columns G:I?

    rylo

  17. #17
    Registered User
    Join Date
    05-20-2008
    Posts
    20
    erm, i mean, no. But I'm trying to avoid using, in case of expansion

    (you can check back at the zip file)
    template(1).xls
    template(2).xls
    template(3).xls

  18. #18
    Forum Expert
    Join Date
    01-15-2007
    Location
    Brisbane, Australia
    MS-Off Ver
    2007
    Posts
    6,591
    Hi

    Are the source files and the main controlling file in the same directory? Are any of the source files being opened when you run the macro?

    I tested using the source files from your original zip file, and when things were all done, I was left with
    Product ID Product Uom Qty
    TDG-**002 Tuna Cheese Pizza Bar KG 90
    RFG-**588 Thai Chicken Fried Rice KG 90
    RFG-**502 Club Sandwich PKT 18
    RFG-**501 Roast Mexican Chicken PKT 90
    RFG-**501 Roast Mexican Chicken pcs 72
    TDG-**002 Tuna Cheese Pizza Bar pcs 90
    RFG-**501 Roast Mexican Chicken KG 60
    in the sheet GrandTotal.


    rylo

  19. #19
    Registered User
    Join Date
    05-20-2008
    Posts
    20
    yup, that's it. That's the output I want. Just funny that it didn't work for me.



    i found also another source code that combines duplicates but I got problem modifying it to suit my needs that us using bounds

    Please Login or Register  to view this content.

  20. #20
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,516
    Sorry guys. this is a CROSS POST.

    This guy is hopeless.

  21. #21
    Forum Expert
    Join Date
    01-15-2007
    Location
    Brisbane, Australia
    MS-Off Ver
    2007
    Posts
    6,591
    Jindon

    Got a link reference? And does he have a solution on the other site?

    rylo

  22. #22
    Registered User
    Join Date
    05-20-2008
    Posts
    20
    yah, there wasn't a reply for a few days that's why I did one here, secondary one at mr.excel(I did mention over there it is linked),
    the original while the other at:
    http://www.mrexcel.com/forum/showthr...07#post1603707


    Really sorry, never came to my mind to link the original to the secondary.

    rylo: no solutions from the other side (other than pivot table).

  23. #23
    Forum Expert
    Join Date
    01-15-2007
    Location
    Brisbane, Australia
    MS-Off Ver
    2007
    Posts
    6,591
    and the answers to my questions are....

  24. #24
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,516
    I can not give the url, because I'm not allowed to copy the url due to the security here.
    However you can easily find the thread under the name of Guanjin, Peter and the title is
    Modify this Code to add-up numbers in COL-D in MrExcel

    Just a note for you, the OP always tend to give us the crue one by one and lead us to the different direction. So I have decided not to answer his thread anymore.

  25. #25
    Registered User
    Join Date
    05-20-2008
    Posts
    20
    rylon: The soultions you gave, my partner is using them. I'm just helping my partner with her work. So we can finish this project in time.

    Thanks for your understanding.
    Last edited by Pukka83; 06-23-2008 at 11:48 PM.

  26. #26
    Forum Moderator davesexcel's Avatar
    Join Date
    02-19-2006
    Location
    Regina
    MS-Off Ver
    MS 365
    Posts
    13,475
    Quote Originally Posted by jindon
    Sorry guys. this is a CROSS POST.

    This guy is hopeless.
    This is a very offending statement... however, I don't believe I have ever read a more confusing thread, hopefully it will all get sorted out.
    Last edited by davesexcel; 06-23-2008 at 11:55 PM.

  27. #27
    Registered User
    Join Date
    05-20-2008
    Posts
    20
    erm, it's alrite
    I did cause him alot of trouble because of the numberous changes my company made, that I need to adjust my code to.
    just hope I can finish this soon :>

  28. #28
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,516
    Quote Originally Posted by davesexcel
    This is a very offending statement... however, I don't believe I have ever read a more confusing thread, hopefully it will all get sorted out.
    Hope you will be able to sort this out.

  29. #29
    Forum Expert
    Join Date
    01-15-2007
    Location
    Brisbane, Australia
    MS-Off Ver
    2007
    Posts
    6,591
    All

    I'm taking
    The soultions you gave, my partner is using them
    to mean a working solution has been found, and closing the thread.

    rylo

  30. #30
    Forum Expert Simon Lloyd's Avatar
    Join Date
    03-02-2004
    Location
    locked in the cage
    MS-Off Ver
    All the ones my homepage shows
    Posts
    3,161
    Not all forums are the same - seek and you shall find

  31. #31
    Forum Expert Simon Lloyd's Avatar
    Join Date
    03-02-2004
    Location
    locked in the cage
    MS-Off Ver
    All the ones my homepage shows
    Posts
    3,161
    User Banned!

Closed Thread

Thread Information

Users Browsing this Thread

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

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