+ Reply to Thread
Results 1 to 8 of 8

Loop based on two values and then Copy based on numbers between the two values

Hybrid View

mintsaucesheep Loop based on two values and... 08-20-2013, 06:59 AM
duffry Re: Loop based on two values... 08-20-2013, 07:12 AM
mintsaucesheep Re: Loop based on two values... 08-20-2013, 07:46 AM
Solus Rankin Re: Loop based on two values... 08-20-2013, 08:10 AM
mintsaucesheep Hi Solus The pasted data... 08-20-2013, 08:34 AM
Solus Rankin Re: Loop based on two values... 08-20-2013, 08:54 AM
mintsaucesheep Re: Loop based on two values... 08-20-2013, 09:05 AM
Solus Rankin Re: Loop based on two values... 08-20-2013, 09:43 AM
  1. #1
    Registered User
    Join Date
    05-29-2013
    Location
    London, UK
    MS-Off Ver
    Excel 2010
    Posts
    5

    Loop based on two values and then Copy based on numbers between the two values

    Hi there and thanks for taking the time to look. I only hope that I can explain myself properly.

    I have a macro that copies and pastes lot of information but have now come to the next point whereby I need it to loop based on the difference between two week numbers that a user selects from combo/input boxes, and to include the original week. I.e. 1 to 5 would repeat 5 times (5-1+1=5). I have managed to do this but the user is having to select from Month and week number combo boxes 5 times which is time consuming.

    What I would like to do is to repeat the macro based on the values above but 1) paste the month (from formula) based on the week number (if the user chose 1 to 52, all of the appropriate months would be pasted) and 2) the next consecutive week number would be pasted based on the week number range. I.e. the original macro has pasted a block of 10 rows of data, the user chose the start week of 1 and the end week of 5. 1 is pasted next to the first block of ten rows and then Jan is pasted next to that. Another block of 10 rows is pasted, then 2 is pasted next to the first block of ten rows and then Jan is pasted next to that. Next would be 3, then 4 and finally 5 with the loop stopping.

    I hope that I have explained this fully, and really hope someone can help

    Many thanks in advance

  2. #2
    Registered User
    Join Date
    05-21-2013
    Location
    UK
    MS-Off Ver
    Excel 2003, 2007, 2010
    Posts
    86

    Re: Loop based on two values and then Copy based on numbers between the two values

    Can you upload something to illustrate what you have/want?
    If I've helped or inspired, please click the star.

  3. #3
    Registered User
    Join Date
    05-29-2013
    Location
    London, UK
    MS-Off Ver
    Excel 2010
    Posts
    5

    Re: Loop based on two values and then Copy based on numbers between the two values

    Hi Duffry, hopefully this will help
    Attached Files Attached Files

  4. #4
    Forum Expert Solus Rankin's Avatar
    Join Date
    05-24-2013
    Location
    Hollywood, CA
    MS-Off Ver
    Win7 Office 2010 VS Express 2012
    Posts
    2,655

    Re: Loop based on two values and then Copy based on numbers between the two values

    I can't tell from you example how far each loop should go. Does the 'Pasted data Country' come from your previous macro? How do you know when a week stops? What if there aren't 5 weeks in that month?
    Thanks,
    Solus


    Please remember the following:

    1. Use [code] code tags [/code]. It keeps posts clean, easy-to-read, and maintains VBA formatting.
    Highlight the code in your post and press the # button in the toolbar.
    2. Show appreciation to those who have helped you by clicking below their posts.
    3. If you are happy with a solution to your problem, mark the thread as [SOLVED] using the tools at the top.

    "Slow is smooth, smooth is fast."

  5. #5
    Registered User
    Join Date
    05-29-2013
    Location
    London, UK
    MS-Off Ver
    Excel 2010
    Posts
    5
    Hi Solus

    The pasted data is from another macro, but to answer your questions, the amount if loops is the difference between the two entered weeks 1 and 5 plus 1. So if the user enters 1 and 5 then the loop would be five and the weeks to be pasted are 1 through to 5. Same if they entered 49 and 52, the loop would be 4 with the weeks 49 through to 52 next to each pasted block of data

    Thanks

  6. #6
    Forum Expert Solus Rankin's Avatar
    Join Date
    05-24-2013
    Location
    Hollywood, CA
    MS-Off Ver
    Win7 Office 2010 VS Express 2012
    Posts
    2,655

    Re: Loop based on two values and then Copy based on numbers between the two values

    Okay, got that part. When I ask how for it should loop, where do we know where week 1 ends and week 2 begins?

  7. #7
    Registered User
    Join Date
    05-29-2013
    Location
    London, UK
    MS-Off Ver
    Excel 2010
    Posts
    5

    Re: Loop based on two values and then Copy based on numbers between the two values

    If I understand right, week 1 should stop at the bottom of the first block of data, then another block will be pasted and the next week will be pasted. Hope that helps

  8. #8
    Forum Expert Solus Rankin's Avatar
    Join Date
    05-24-2013
    Location
    Hollywood, CA
    MS-Off Ver
    Win7 Office 2010 VS Express 2012
    Posts
    2,655

    Re: Loop based on two values and then Copy based on numbers between the two values

    Can you post the workbook that has the macro that pastes the original data?

    Are the weeks pasted by the first macro done all at the same time? Is a weeks work of data added each time the macro is run or all data show added each time?

+ 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. Need help making a macro to copy range of values based on cell values.
    By zolton in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 06-23-2013, 08:58 AM
  2. Insert New row in another sheet and Loop based on values in certain cells
    By acsishere in forum Excel Programming / VBA / Macros
    Replies: 16
    Last Post: 05-14-2013, 02:25 PM
  3. Running Macro with Do Loop of similar based on values in a Column
    By fishycarl in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 04-11-2013, 03:50 AM
  4. how to loop Criteria based on unique values in a column
    By excelkeechak in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 04-03-2009, 11:01 AM
  5. Need to loop through rows and copy values based on criteria
    By Nice in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 01-21-2005, 08:49 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