+ Reply to Thread
Results 1 to 7 of 7

How to write a Loop within a Loop?

  1. #1
    Registered User
    Join Date
    10-05-2012
    Location
    Huntington Beach, CA
    MS-Off Ver
    Excel 2007
    Posts
    14

    How to write a Loop within a Loop?

    - Loop within a loop
    o The Loop is supposed to perform the following tasks here below:
    1.)Copy Product ID number from Column A in “Sheet 1”, and then loop through “.jpg” files in column A in “Sheet 2”.
    Basically, the jpg files for a product ID in sheet 1 will be found in Column A of Sheet 2.
    2.)There may be several images or jpg files per product. If there are lets say 2 images for product ID# 641, then the values would be copied and then pasted into columns C and D of the same row as Product ID 641.
    3.)If a product has 6 pictures e.g. Product ID 830, the images would be pasted into columns C, D, E, F, G, and H of the same row as Product ID 830 (in this case row 6 of Sheet 1).
    I hope this makes sense. I know how to create a basic Loop, but I have no idea how to create a Loop within a Loop. I wanted to practice this skill and have been trying for some time, but I can’t get my code to work. Any help would be greatly appreciated.
    Thanks
    Attached Files Attached Files
    Last edited by kitcargray; 10-30-2012 at 04:05 PM.

  2. #2
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: How to write a Loop within a Loop?

    You don't say why you are looping through column A on 'Sheet2'.

    Are you looking for something? eg the product ID

  3. #3
    Registered User
    Join Date
    10-05-2012
    Location
    Huntington Beach, CA
    MS-Off Ver
    Excel 2007
    Posts
    14

    Re: How to write a Loop within a Loop?

    Hi Norie, Thanks for your reply.
    I am looping through Column A on sheet 2, to grab the JPGs that correspond/match to the Product ID numbers on sheet 1.

    Those jpg file cells will be then copied and pasted the rows of the corresponding product ID on sheet 1.

  4. #4
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: How to write a Loop within a Loop?

    I take it in the workbook sheet 2 is actually 'Sheet1' and 'Shopatron_Intl_Product_Image_S' is sheet 1?

  5. #5
    Registered User
    Join Date
    10-05-2012
    Location
    Huntington Beach, CA
    MS-Off Ver
    Excel 2007
    Posts
    14

    Re: How to write a Loop within a Loop?

    Sorry, yes. I mixed up the sheet names. The correct file is the 36.4KB file. I attached a new one.
    Thanks for your time and help.
    Last edited by kitcargray; 10-30-2012 at 04:07 PM.

  6. #6
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: How to write a Loop within a Loop?

    You might not need 2 loops.

    Give this a try, it works but I don't know how accurate it is.

    I'm think there are some mismatchs but I can't pinpoint any right now.
    Please Login or Register  to view this content.

  7. #7
    Registered User
    Join Date
    10-05-2012
    Location
    Huntington Beach, CA
    MS-Off Ver
    Excel 2007
    Posts
    14

    Re: How to write a Loop within a Loop?

    Norie,
    Your skills are absolutely amazing. Yes, your code works and I can't thank you enough. I can only dream of someday getting to a tenth of the coding skills you guys have.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Tags for this Thread

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