+ Reply to Thread
Results 1 to 10 of 10

Need VBA to Create Sentence Based On Criteria

  1. #1
    Forum Contributor
    Join Date
    08-06-2012
    Location
    United States
    MS-Off Ver
    Excel 2013
    Posts
    119

    Need VBA to Create Sentence Based On Criteria

    Hello,
    *I should say before hand that this might be a confusing explanation, but hopefully the example workbook I am uploading will make more sense.

    I have a couple of questions. I need to run a report that we gives to our customers that tells them what products are still available in the most concise way. All of our products are organized into classes. There are a ton of classes, but if it contains the letter 'C' that means it is closed out and no longer available. Each of our products comes in several different colors and sometimes only certain colors are available.

    I already have formulas that count the total number of colors for each product and the number of colors for each product that are closed out. If all of the colors are closed out I need it to say: [PRODUCT NAME] - All out. If all of the colors are available I need it to say: [PRODUCT NAME] - All good. The tricky part is that if only some of the colors are out, I need a sentence that will say which colors are good or bad in the most concise way. For example, if there are 4 good colors and 3 closed out colors, it is more concise to say which colors are out so it would look like this: [PRODUCT NAME] - [COLOR1], [COLOR2], [COLOR3] Out. On the other hand if there are 2 good and 5 out its more concise to say: [PRODUCT NAME] - [COLOR1], [COLOR2] Good.

    That is my first question. My second question is if there is a VBA sub that could take the place of the countif functions on the sheet. The sheet is going to be massive (more than 10,000 lines) and even two countif formulas on a sheet that big make the calculation time so incredibly slow.

    Thanks in advance for any help, below is my sample workbook.

    Example.xlsx

  2. #2
    Forum Expert nilem's Avatar
    Join Date
    10-22-2011
    Location
    Ufa, Russia
    MS-Off Ver
    2013
    Posts
    3,377

    Re: Need VBA to Create Sentence Based On Criteria

    Hi chaddug.
    try to use this formula in column 'E' (not the whole column B:B, and only a specific range B3:B10000)
    Formula: copy to clipboard
    Please Login or Register  to view this content.

  3. #3
    Forum Contributor
    Join Date
    08-06-2012
    Location
    United States
    MS-Off Ver
    Excel 2013
    Posts
    119

    Re: Need VBA to Create Sentence Based On Criteria

    Thanks Nilem, Ill try that. Any suggestions on the first part of my question? I appreciate the suggestion, but that is sort of a moot point if I cant get the first part to work.

    Thanks again!

  4. #4
    Forum Contributor
    Join Date
    01-09-2009
    Location
    Cedar Hill, Tx
    MS-Off Ver
    Excel 2003
    Posts
    200

    Re: Need VBA to Create Sentence Based On Criteria

    For a particular Component, a class of "F" would indicate that the item is good - correct?

    Bob

  5. #5
    Forum Expert nilem's Avatar
    Join Date
    10-22-2011
    Location
    Ufa, Russia
    MS-Off Ver
    2013
    Posts
    3,377

    Re: Need VBA to Create Sentence Based On Criteria

    and what the result should be in this case (two "out" and two "good")
    BEYOND THE PINE BLUE C
    BEYOND THE PINE GERY CZ
    BEYOND THE PINE YELLOW F
    BEYOND THE PINE ORANGE F

  6. #6
    Forum Contributor
    Join Date
    08-06-2012
    Location
    United States
    MS-Off Ver
    Excel 2013
    Posts
    119

    Re: Need VBA to Create Sentence Based On Criteria

    Yes, anything without a C is good. And I dont suppose I really care which way it goes if there are equal good and out, I guess just go with good if they are equal.

  7. #7
    Forum Expert
    Join Date
    07-31-2010
    Location
    California
    MS-Off Ver
    Excel 2007
    Posts
    4,070

    Re: Need VBA to Create Sentence Based On Criteria

    Give this a try

    Please Login or Register  to view this content.

  8. #8
    Forum Contributor
    Join Date
    08-06-2012
    Location
    United States
    MS-Off Ver
    Excel 2013
    Posts
    119

    Re: Need VBA to Create Sentence Based On Criteria

    Quote Originally Posted by stnkynts View Post
    Give this a try

    Please Login or Register  to view this content.
    Thanks stnkynts, Im not at my desk at the moment, so I cant test it out, but looking over it there are 2 things I noticed that I think might be a problem, but I could be wrong. First the good products aren't always 'F' they could be 'E' 'O' 'OJ' 'EO' 'OZ' and probably a couple of other things that I'm not remembering. Looking at your code, it looks like it is looking specifically for 'F's, when it should be looking for anything that does not contain a 'C'. Second, it looks like it is only going to say either All Good, [Colors] - Out or All Out. The All Out or All Good is fine, but it needs to decide if there are more that are Good, or more that are Out, and pic the one that has the least in that category. Does that make sense?

    Thanks again though, this is much farther than I was.

  9. #9
    Forum Expert
    Join Date
    07-31-2010
    Location
    California
    MS-Off Ver
    Excel 2007
    Posts
    4,070

    Re: Need VBA to Create Sentence Based On Criteria

    Yeah it only looks for F & C. Best of luck finding a solution to your problem.

  10. #10
    Forum Contributor
    Join Date
    08-06-2012
    Location
    United States
    MS-Off Ver
    Excel 2013
    Posts
    119

    Re: Need VBA to Create Sentence Based On Criteria

    I have modified your code a bit, and it think its mostly doing what I need. But it doesn't seem to work when its supposed to say All Out. It just lists all of the colors and says out. Any idea why?

    Here is the workbook I'm using: Example2.xlsm

    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)

Similar Threads

  1. Replies: 11
    Last Post: 07-04-2014, 07:10 AM
  2. [SOLVED] Create Sentence using other cells
    By blacky1 in forum Excel General
    Replies: 3
    Last Post: 04-20-2012, 10:01 PM
  3. Excel 2007 : create a sentence from 4 cells
    By NavNeet2912 in forum Excel General
    Replies: 2
    Last Post: 04-22-2011, 11:03 AM
  4. MACROS: Sort by multiple criteria - Create tabs based off of criteria
    By svineyard in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 07-21-2009, 10:48 AM
  5. Find if 4 criteria in a sentence
    By eitancoh in forum Excel General
    Replies: 4
    Last Post: 08-14-2008, 05:04 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