+ Reply to Thread
Results 1 to 26 of 26

If statement check

  1. #1
    Registered User
    Join Date
    12-03-2008
    Location
    Chicago
    Posts
    13

    If statement check

    I would like this code to check if there is already something in the cell, and if so, add a comma and space, then output the next appropriate condition of the if statement. The way I have the code written currently, it checks one column to see if a word exists, then if so, it outputs a word associated with this condition. Under this method, the code does not take account for columns that have more than one matching word. I've included a small portion of the code, there are more elseif statements, but they are redundant for this purpose. Thanks in advance for your help!!!

    Please Login or Register  to view this content.
    Last edited by VBA Noob; 12-03-2008 at 02:50 PM.

  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,259
    Hello Royalmathmtcs,

    Welcome to the Forum!

    To get an accurate and quick solution to your problem, it would help to know how the data is laid out in the workbook. The easiest way to do this is to post your workbook for review. If you are using Excel 2007 then you should also post a copy in Excel 2003 format also.

    Sincerely,
    Leith Ross

  3. #3
    Registered User
    Join Date
    12-03-2008
    Location
    Chicago
    Posts
    13
    Thanks for the reply Leith, I attached an example.
    Attached Files Attached Files

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

    Will you be adding to the list in the future?

    Sincerely,
    Leith Ross

  5. #5
    Registered User
    Join Date
    12-03-2008
    Location
    Chicago
    Posts
    13
    I posted an small example of what I have, as there are about 1000 entries. To answer your question, no I will not have to add any more entries to this list.

  6. #6
    Forum Contributor
    Join Date
    02-19-2005
    Location
    Gurgaon,India
    MS-Off Ver
    2007,2010,2013
    Posts
    180
    Hi,

    Here is a sample. Work on this.

    Please Login or Register  to view this content.
    HTH
    Last edited by Krishnakumar; 12-03-2008 at 09:57 PM.
    Kris

  7. #7
    Registered User
    Join Date
    12-03-2008
    Location
    Chicago
    Posts
    13
    That looks like it might work. The sample you have provided outputs everything to the same column it is gathering the information from to check within the array, erasing data that needs to stay in that column. How do I move the output from this code into column N, starting at the same row as column M?

  8. #8
    Registered User
    Join Date
    12-03-2008
    Location
    Chicago
    Posts
    13
    Nevermind about finding the correct column to output to, time to see if this works for the entire workbook!

  9. #9
    Registered User
    Join Date
    12-03-2008
    Location
    Chicago
    Posts
    13
    I added a few more arrays and have the code working, but it doesnt add a comma to the end of the previous entry in the new column. It is overwriting anything in the column that should be kept. For example, if there is a scenerio where there is more than one match is found in the column the array is checking, it will output the match from the array further down in the code, rather than placing a comma behind the first entry and then adding the second match. What needs to be modified?

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

    I have found you have duplicate entries for the following types:

    UL 1863 Twice in ITE
    UL 1450 Twice in Appliances
    UL 1678 Twice in Consumer Electronics

    These occur in both HVAC and Insulating Materials

    UL 2353
    UL 1692
    UL 224
    UL 1441
    UL 1696
    UL 969

    What do you want to do with these?

    Sincerely,
    Leith Ross

  11. #11
    Registered User
    Join Date
    12-03-2008
    Location
    Chicago
    Posts
    13
    Leith,

    I might have misunderstood your question about adding to the list. The list of entries in the macro are not complete and I am currently adding more. As for the excel list, that is complete, except for what needs to be added under this macro. Thanks for pointing out those duplicates. It would be desirable for the macro to output both when there is a duplicate i.e if UL 2353 exists under HVAC and Insulating Materials, then then column N should be filled with HVAC, Insulating Materials.

    I think that Krishnakumar's example is heading in the correct direction, but the problem it is having is that if column M contains an entry in a single cell that has UL 1863 under ITE, and UL 1450 under Appliances, it will only output Appliances in column N, instead of ITE, Appliances. I think this has something to do with the placement of the split fuction, but I am only speculating.

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

    I have been using some other techniques to handle the data. Currently, I am employing a collection object to hold all the industry types, which alerted me to the duplication. It works well with the exception each entry must be unique.

    The collection allows for a UDF (User Defined Function) to placed on the worksheet. It is called just like a regular worksheet function.
    Please Login or Register  to view this content.
    It returns the types in comma separated list in cell "N". I'll keep working on it.

    Sincerely,
    Leith Ross

  13. #13
    Forum Contributor
    Join Date
    02-19-2005
    Location
    Gurgaon,India
    MS-Off Ver
    2007,2010,2013
    Posts
    180
    Hi,

    Try,

    change the for....next except "ITE"

    Please Login or Register  to view this content.
    HTH

  14. #14
    Registered User
    Join Date
    12-03-2008
    Location
    Chicago
    Posts
    13
    Krishnakumar, I really appreciate your help!

    I changed that segment that you posted, and now the code properly implements the comma that was missing before. I added more arrays and For Next statements and now I am running into the problem of not getting the correct output from the for next statement. I think this is because the way that you showed me only cosiders a scenerio with two arrays.

    An example would be for UL 489. When the code looks for this it should see that its in the power distributions array, and output power distributions in the N column. Instead, the code is outputing ITE, Consumer Electronics, Power Distribution, Security & Signal in the N column. In one case I found with multiple entries in the M column, it didn't even output Power Distribution when UL 489 was present. Here is the code that I have now. I cut out most of the array section, as that has been entered correctly. What do I need to do from here?

    Please Login or Register  to view this content.

  15. #15
    Registered User
    Join Date
    12-03-2008
    Location
    Chicago
    Posts
    13
    Ok, I figured it out...The For Next statement for ITE needs to have the is else, ifempty check in it as well, not just for the sequential statements.

    Please Login or Register  to view this content.
    Thank you for the help, I couldn't have done this without you!!!!

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

    This version loads each industry type from its own array into a collection object. The macro uses the collection to recall the industry type name for the standard. No duplicates are listed in column "N". If any standard has not been entered, you will see #Value! displayed in the cell. Have look and let me know if you have any questions.

    Sincerely,
    Leith Ross
    Attached Images Attached Images
    Attached Files Attached Files

  17. #17
    Registered User
    Join Date
    12-03-2008
    Location
    Chicago
    Posts
    13
    Hi Leith,

    This version looks a lot cleaner, and it appears that it will not enter duplicate industry names in the column, which is the only problem with the other code I was able to get working.

    I believe that this is to be ran with =GetIndustryType()?

    Also, if I were to add more keys with standard numbers, ie
    Please Login or Register  to view this content.
    would I need to make this value higher?
    Please Login or Register  to view this content.
    Last edited by Royalmathmtcs; 12-04-2008 at 06:49 PM.

  18. #18
    Registered User
    Join Date
    12-03-2008
    Location
    Chicago
    Posts
    13
    This is working very well now, is there any way to modify it so that #Value! only shows up when there isn't a single match in the standards column? The way it is right now, #Value! shows even when there is a matching standard available along with a standard that hasn't been defined yet.

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

    You are correct about the macro. Since it is a UDF, it is called just like a standard worksheet formula. If you have more than 100 Standards per Industry name then you will need to increase the Keys array value. I was thinking that it might be good to load the standards from a worksheet. It would be easier to maintain and allow you to easily search for a standard, or sort them.

    Sincerely,
    Leith Ross

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

    I can change the macro not to error on a non existent standard. I left it that way as an alert to the user that something wasn't right. What would you like it do?

    Sincerely,
    Leith Ross

  21. #21
    Registered User
    Join Date
    12-03-2008
    Location
    Chicago
    Posts
    13
    Leith,

    Is there a way to display: (error for any non existent standard) comma (industry for defined standard)? This way the user would be notified of the error, but still be able to see if there is an industry available for the company. If not, could you explain how to make is so that it does nothing for the error, and displays the industry for the standards that have been defined, even if they are in the same cell as a non defined standard?
    Last edited by Royalmathmtcs; 12-04-2008 at 07:18 PM.

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

    I could display the missing standards in a message box. Would that work?

    Sincerely,
    Leith Ross

  23. #23
    Registered User
    Join Date
    12-03-2008
    Location
    Chicago
    Posts
    13
    Yes, that would be great, as long as it still displays the industry for the standards that have been defined, even if they are in the same cell as a non defined standard.

    I really appreciate your time and patience...

  24. #24
    Forum Contributor
    Join Date
    02-19-2005
    Location
    Gurgaon,India
    MS-Off Ver
    2007,2010,2013
    Posts
    180
    Hi,


    Please Login or Register  to view this content.
    HTH

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

    I have added the message box to alert you which standards are missing. All other standards will have the industry to which they belong listed. The standards havae been removed from the body of the macro and placed on a separate worksheet. This will make it easier to update the standards and industries.

    Sincerely,
    Leith Ross
    Attached Files Attached Files

  26. #26
    Forum Contributor
    Join Date
    02-19-2005
    Location
    Gurgaon,India
    MS-Off Ver
    2007,2010,2013
    Posts
    180
    Hi,

    Add a worksheet and name it "IndustryType"
    Add all unique standards in Col a
    In Col b put all industry types separated by a comma corresponding to the standards.

    And try this code.

    Please Login or Register  to view this content.
    HTH

+ 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