+ Reply to Thread
Results 1 to 7 of 7

Vba loop

  1. #1
    Registered User
    Join Date
    09-11-2014
    Location
    PR
    MS-Off Ver
    Excel 2007
    Posts
    6

    Vba loop

    Hi All,


    New to coding, looking for a way to do a loop I guess is the best way.


    I have column H with 7,000 lines of ID's.

    I need to copy and paste those lines 6 times.

    Then I sort them and on column O write numbers 1-6 . The loop is for those 7000 Ids to have one number each.

    Samething on column N (this time with text)

    End when there is no more text on column H.

    Example:

    H N O
    ID1 A 1
    ID1 B 2
    ID1 C 3
    ID1 D 4
    ID1 E 5
    ID1 F 6
    ID2 A 1
    ID2 B 2
    ID2 C 3
    ID2 D 4
    ID2 E 5
    ID2 F 6
    ID3 A 1
    ID3 B 2
    ID3 C 3
    ID3 D 4
    ID3 E 5
    ID3 F 6



    I would like to thank anyone who can help in advance! I'm desperate! Thanks!

  2. #2
    Registered User
    Join Date
    06-23-2014
    Location
    India
    MS-Off Ver
    2013
    Posts
    20

    Re: Vba loop

    Hi,

    You can use For Next loop to copy paste your data repeatedly. Then on column O you can apply countif formula by locking the first cell instead of whole range.
    It will work perfectly. For column N, you can use Vlookup or directly replace the numbers, with your text

  3. #3
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: Vba loop

    Maybe:

    Please Login or Register  to view this content.

  4. #4
    Registered User
    Join Date
    09-11-2014
    Location
    PR
    MS-Off Ver
    Excel 2007
    Posts
    6

    Re: Vba loop

    Wow thanks for the propmtly response, however the code is giving out a space betwen every six lines. I tired puting do until x=1 insted of 0 but gives the samething one space between each ID. Also it takes quite a while not sure if its because of the spaces.

    Its looking greattt but has that small problem.
    How can we fix that.

    Thanks again!

  5. #5
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: Vba loop

    Try:

    Please Login or Register  to view this content.
    The red input should take out the blanks? I did on some dummy data I made up for testing?

  6. #6
    Registered User
    Join Date
    09-11-2014
    Location
    PR
    MS-Off Ver
    Excel 2007
    Posts
    6

    Re: Vba loop

    Bhavsarankit can you explain your reasoning with a few lines of code if possible! I would be really appreciate it.

  7. #7
    Registered User
    Join Date
    09-11-2014
    Location
    PR
    MS-Off Ver
    Excel 2007
    Posts
    6

    Re: Vba loop

    Thanks again John but unforgtunately is not working! It's still giving up a blank space between them.

    Also takes like 4 seconds for every line and i have over 50,000 lines!

+ 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. Find function in nested loop breaking down - not on first time through loop
    By adamstarr12 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 10-07-2014, 04:59 PM
  2. [SOLVED] Copy dynamically changing column and Paste using VBA Loop (Loop within Loop)
    By nixon72 in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 02-12-2013, 12:46 PM
  3. Why did an inner loop variable start overwriting the outer loop range suddenly?
    By 111StepsAhead in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 05-16-2012, 03:24 PM
  4. Replies: 0
    Last Post: 07-20-2010, 11:42 AM
  5. Loop a column on Sheet1 and loop a row on Sheet2 to find a match
    By johnnywinter in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 02-13-2009, 02:09 PM

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