+ Reply to Thread
Results 1 to 7 of 7

Loop through range names for location of dynamic paste

  1. #1
    Valued Forum Contributor AlvaroSiza's Avatar
    Join Date
    09-19-2007
    Location
    Staffordshire
    MS-Off Ver
    2007
    Posts
    591

    Loop through range names for location of dynamic paste

    Key points,

    - I am currently importing tabular data from anywhere between 5 and 7 worksheets.
    - I am grabbing the data from each and pasting (end(x1up)) to a single dump worksheet.
    - I am then using a Do While Loop to analyze for instances of two strings (using inStr - the beginning and end of a selected range).
    - Once this range is selected, I am stair-stepping down and to the right for my paste by a factor of 17 columns and 100 rows.

    Here's the code:
    Please Login or Register  to view this content.
    **Request**
    I have since named 6 ranges that I would like to loop through to tell excel where I want each subsequent range pasted after analysis and selection.cut. The ultimate goal is to have the data pasted to the same place everytime regardless of the dynamic nature of the imported data. The ranges are A_1, B_1, C_1, A_2, B_2, and C_2.

    THANK YOU!

  2. #2
    Forum Expert davegugg's Avatar
    Join Date
    12-18-2008
    Location
    WI, US
    MS-Off Ver
    2010
    Posts
    1,884

    Re: Loop through range names for location of dynamic paste

    How about creating an array of the ranges, then looping through the array?
    Is your code running too slowly?
    Does your workbook or database have a bunch of duplicate pieces of data?
    Have a look at this article to learn the best ways to set up your projects.
    It will save both time and effort in the long run!


    Dave

  3. #3
    Valued Forum Contributor AlvaroSiza's Avatar
    Join Date
    09-19-2007
    Location
    Staffordshire
    MS-Off Ver
    2007
    Posts
    591

    Re: Loop through range names for location of dynamic paste

    Could you possibly provide me with an example of how to incorporate into the provided code?

  4. #4
    Forum Expert davegugg's Avatar
    Join Date
    12-18-2008
    Location
    WI, US
    MS-Off Ver
    2010
    Posts
    1,884

    Re: Loop through range names for location of dynamic paste

    Well, I can't really tell by looking at your code where the named ranges are supposed to fit in. Here is a generic example of looping through an array of ranges.

    Please Login or Register  to view this content.
    If you need more detail you'll have to provide a more detailed description of what your code should do, or post a sample workbook, which is always a good option.

  5. #5
    Valued Forum Contributor AlvaroSiza's Avatar
    Join Date
    09-19-2007
    Location
    Staffordshire
    MS-Off Ver
    2007
    Posts
    591

    Re: Loop through range names for location of dynamic paste

    Thanks Dave. I have simplified down to a vanilla example. ABCD populate A1:A4. B1:B4 is a named range containing the string text of 4 other named ranges in the worksheet (C5, D6, E7, and F8, respectively. I need to loop through the first, cut it, and paste it to the range indicated in the second loop.

    Ultimately C5="A", D6="B", E7="C", and F8="D"

    My effort is included in Module 1.
    Attached Files Attached Files

  6. #6
    Valued Forum Contributor AlvaroSiza's Avatar
    Join Date
    09-19-2007
    Location
    Staffordshire
    MS-Off Ver
    2007
    Posts
    591

    Re: Loop through range names for location of dynamic paste

    Ok, so I ran with the loops and can get the first one to work, but need assistance exiting the loop back into the outer loop. Attached for reference. Code is in module 1. I'm learning. Much appreciated!

    Please Login or Register  to view this content.
    2 caveats:

    1. After the paste occurs I lose the named range of the destination cell.
    2. I would prefer to have A1:A4 be text as opposed to numbers, but I could not get
    Please Login or Register  to view this content.
    *From Andy Pope contribution found here: http://www.ozgrid.com/forum/showthre...682#post143682

    To work in place of the
    Please Login or Register  to view this content.
    Used herein.

    Thanks!
    Attached Files Attached Files
    Last edited by AlvaroSiza; 08-16-2011 at 08:31 PM.

  7. #7
    Forum Expert davegugg's Avatar
    Join Date
    12-18-2008
    Location
    WI, US
    MS-Off Ver
    2010
    Posts
    1,884

    Re: Loop through range names for location of dynamic paste

    This should fix all your issues:

    Please Login or Register  to view this content.

+ Reply to 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