+ Reply to Thread
Results 1 to 13 of 13

Looping Subject to a Condition

  1. #1
    Forum Contributor
    Join Date
    02-08-2005
    MS-Off Ver
    Microsoft 365
    Posts
    839

    Looping Subject to a Condition

    Hi,

    In A1:A1000 I have a list of product names; Product A, Product B etc, each appearing more than once. I would like to create a simple macro that extracts from column A, and puts into a new range starting at C1, each of the names of the products. So C1 would contain the text "Product A", C2 would contain the text "Product B" etc until column C contains the list of product names from A1:A1000.

    In a previous thread someone kindly suggested the following code which works perfectly:

    Please Login or Register  to view this content.
    I would now like to amend this code so that it only returns to column C those names from column A that have the word “Confirmed” in the adjacent cell in column B.

    Can someone please suggest a VBA solution?

    Thanks!
    Last edited by andrewc; 09-11-2013 at 08:41 AM.

  2. #2
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: Looping Subject to a Condition

    What you need is auto filter. You can do it yourself using filter function. Just filter column A by “Confirmed” and copy the filtered cells in to column B.

  3. #3
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,482

    Re: Looping Subject to a Condition

    You can use the Criteria argument to further filter the data.

    Please Login or Register  to view this content.
    Assumes cells J1 and J2 are empty and will temporarily be used to store criteria.
    column B has a header of Status
    Last edited by Fotis1991; 09-11-2013 at 08:28 AM.
    Cheers
    Andy
    www.andypope.info

  4. #4
    Forum Expert Debraj Roy's Avatar
    Join Date
    09-27-2012
    Location
    New Delhi,India
    MS-Off Ver
    Excel 2013
    Posts
    1,469

    Re: Looping Subject to a Condition

    In case if you are looking only to copy Column A..

    you can follow snb's technique for unique with criteria..

    Please Login or Register  to view this content.
    Regards!
    =DEC2HEX(3563)

    If you like someone's answer, click the star to give them a reputation point for that answer...

  5. #5
    Forum Expert Fotis1991's Avatar
    Join Date
    10-11-2011
    Location
    Athens(The homeland of the Democracy!). Greece
    MS-Off Ver
    Excel 1997!&2003 & 2007&2010
    Posts
    13,744

    Re: Looping Subject to a Condition

    @ andrewc

    We are waiting from a long time member to knows the forum rules. Pls use code tags for your codes.

    This time and only this i did it for you. I hope that will not need again to say something like this.

    Pls, you the old members, do Moderators life a little easier!
    Regards

    Fotis.

    -This is my Greek whisper to Europe.

    --Remember, saying thanks only takes a second or two. Click the little star * below, to give some Rep if you think an answer deserves it.

    Advanced Excel Techniques: http://excelxor.com/

    --KISS(Keep it simple Stupid)

    --Bring them back.

    ---See about Acropolis of Athens.

    --Visit Greece.

  6. #6
    Forum Contributor
    Join Date
    02-08-2005
    MS-Off Ver
    Microsoft 365
    Posts
    839

    Re: Looping Subject to a Condition

    Apologies for the lack of code tags - while I've used this forum a quite a lot I don't think that I've ever posted VBA code and wasn't aware of the need to use tags.

    I'll be sure to use tags from now on!

  7. #7
    Forum Expert Fotis1991's Avatar
    Join Date
    10-11-2011
    Location
    Athens(The homeland of the Democracy!). Greece
    MS-Off Ver
    Excel 1997!&2003 & 2007&2010
    Posts
    13,744

    Re: Looping Subject to a Condition

    Your understanding is really appreciated!

  8. #8
    Forum Contributor
    Join Date
    02-08-2005
    MS-Off Ver
    Microsoft 365
    Posts
    839

    Re: Looping Subject to a Condition

    Thank you all for the suggestions

  9. #9
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: Looping Subject to a Condition

    Fotis,
    I did not know you are a forum moderator. I am always curious why the other sites such as Cage Code do not ask for code tags, the code is auto wrapped in tags?

  10. #10
    Forum Contributor
    Join Date
    01-18-2013
    Location
    Prague, Czech rep.
    MS-Off Ver
    Excel 2003 - 2016
    Posts
    138

    Re: Looping Subject to a Condition

    Hi andrewc,

    if i may suggest I´d use just a function:

    =if("target cell" = "comfirmed";A#;"")

    and copy it all the way down (instead of target cell use the address where comfirmed should ocur; instead of # use the number of the row wher you´re placing the function.

    I feel like this should do the trick if i understood your issue correctly, or you still want to have uniq selection in column C? if so I´d suggest advanced filtering

  11. #11
    Forum Expert Fotis1991's Avatar
    Join Date
    10-11-2011
    Location
    Athens(The homeland of the Democracy!). Greece
    MS-Off Ver
    Excel 1997!&2003 & 2007&2010
    Posts
    13,744

    Re: Looping Subject to a Condition

    Quote Originally Posted by AB33 View Post
    Fotis,
    I did not know you are a forum moderator. I am always curious why the other sites such as Cage Code do not ask for code tags, the code is auto wrapped in tags?
    I am since yesterday! New one!

    http://www.excelforum.com/the-water-...94#post3401394

    I don't know why other forums don't use these. How i could i?

    Our forum rules reqired code tags arount the code and as Moderator i am here trying to keep the rules alive!

  12. #12
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: Looping Subject to a Condition

    Fotis,
    "I don't know why other forums don't use these"

    They do, but the OP has not required to use code tags-That is the whole point. When one posts their code, the code appeared with code tags auto-wrapped-no need for human intervention.

  13. #13
    Forum Expert Fotis1991's Avatar
    Join Date
    10-11-2011
    Location
    Athens(The homeland of the Democracy!). Greece
    MS-Off Ver
    Excel 1997!&2003 & 2007&2010
    Posts
    13,744

    Re: Looping Subject to a Condition

    I am not the one that can answer to this. I believe that you can understand this.

    And as this thread is not the right place to duscuss it, pls make your question in Suggestion for Improvment, sub forum. Perhaps Admins can offer you an answer.

+ 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. Replies: 5
    Last Post: 07-26-2013, 10:43 AM
  2. Sum the product of 3 ranges subject to an if condition array
    By John Vieren in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 11-10-2012, 05:56 AM
  3. Replies: 3
    Last Post: 08-07-2009, 12:03 PM
  4. [SOLVED] looping for a condition
    By jhahes in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 09-30-2005, 07:05 PM
  5. Auto Run Excel macro subject to condition
    By Warrior1800 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 07-23-2005, 08:05 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