+ Reply to Thread
Results 1 to 3 of 3

VBA Loops

  1. #1
    Registered User
    Join Date
    08-16-2011
    Location
    USA
    MS-Off Ver
    Excel 2003
    Posts
    1

    Question VBA Loops

    Hello,

    I am having a lot of trouble figuring out this script. I need to move some cells around on a very large spreadsheet.

    I have 5 columns.
    I have items, 2 columns in between, data and a new column for data

    Item #_____Col 1__________Col 2 ________Data ________________new column data

    Item1____ 798-3A01 ____ No Value______SANITARY WATER____*insert 51.00 here_
    Item2____ 798-3A02 ____ No Value______ 100.00____________________
    Item3____ 798-3A03 ____ No Value ______51.00____________________


    I want to take the data for Item3 (51.00) and cut and paste it to the new column for data on the same row as Item1 (would be next to SANITARY WATER). I have to do this almost 10,000 times.

    Seems easy, except the Item # list is not consistent. Sometimes it skips numbers, so I have to include Do Until loops to find the row Item1 is on, and then tell it to go to the right to the new column for data and paste.

    Here is my problem: The Do until loops keep going up to the row with Item2, not Item1. Something I am telling it to do is making it go to just below where I need it to be. So then it goes right like I want it to, pastes in the right column, wrong row.

    My code then goes back to find the 'Item3' cell and goes one down so it can reiterate the script on the next item. It uses the exact same loop and it does this correctly.


    Here is my code:

    Please Login or Register  to view this content.
    Last edited by mistadarcy; 08-16-2011 at 12:49 PM. Reason: included code tags

  2. #2
    Forum Expert Whizbang's Avatar
    Join Date
    08-05-2009
    Location
    Greenville, NH
    MS-Off Ver
    2010
    Posts
    1,395

    Re: Excel VBA Loops HELP!!

    Why not use Match()?

    Please Login or Register  to view this content.

  3. #3
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: Excel VBA Loops HELP!!

    Loops are very ineficient, add that to the fact that your code is constantly selecting cells & it could potentially be extremely slow. I would use AutoFilter, automated with VBA.

    Attach an example workbook
    Hope that helps.

    RoyUK
    --------
    For Excel Tips & Solutions, free examples and tutorials why not check out my web site

    Free DataBaseForm example

+ 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