+ Reply to Thread
Results 1 to 3 of 3

Loop through cells and add rows based on multiple criteria

  1. #1
    Registered User
    Join Date
    01-21-2005
    Posts
    2

    Arrow Loop through cells and add rows based on multiple criteria

    Hello to all,

    I'll start by saying that I am pretty new to VBA and might be quite spotty with my knowledge. So, if I seem to be at a fault because I don't know the basics I apologize. Just excuse any obvious things I've missed. I don't mind having things explained in a degrading manner.

    Anyways...

    I'm writing macros to process my data into printable invoices. I've been doing pretty well with stage 1 (preparing the list of data) but am stuck at the end. In this case the important data fields are my "Card #" and my "Product #". I have all my data sorted ascending, 1st by "Card #" and 2nd by "Product #". A common set of entries looks like this...

    Card # -- Prod #
    848001 - 1
    848001 - 1
    848001 - 1
    848001 - 1
    848001 - 2
    848001 - 2
    848002 - 1
    848002 - 1
    848003 - 1

    I need to have a loop go through all the entries and add a row at the end of EVERY Product # per Card #. So in the above case I would need it to look like this in the end...

    Card # -- Prod #
    848001 - 1
    848001 - 1
    848001 - 1
    848001 - 1

    848001 - 2
    848001 - 2

    848002 - 1
    848002 - 1

    848003 - 1

    ...of course I would do additional formatting to the added rows but I think if I could get this far I could manage the rest on my lonesome.

    I've tried a few things. For example I've tried using a 'For Each Next' loop with nested 'If Then Else' statements in it. I had the 'If Then Else' statements running against the values of the previous cells. If they differed in either column I added a row. Unfortunately I couldn't succeed in my attempt.

    Any suggestions or examples would be GREATLY appreciated. I've been trying all night and would love for a little help.


  2. #2
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258
    Hello Northern Hybrid,

    I wrote some code not to long ago to format a worksheet the way you want. Before I give the code, I would like to know if the Card # and Product # are in separate columns. If they are I need to make a minor change so you can use it.
    Please let know. You can e-mail [email protected]

    Hope this helps,
    Leith Ross

  3. #3
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,525
    Hi

    assuming col.A has Card# and Col.B has Prod.#

    try the code
    Please Login or Register  to view this content.
    hope this helps

    jindon
    Last edited by jindon; 01-21-2005 at 06:41 AM.

+ 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