+ Reply to Thread
Results 1 to 7 of 7

Alternative to multipe ELSE IF statements?

  1. #1
    Registered User
    Join Date
    05-16-2012
    Location
    Ontario
    MS-Off Ver
    Excel 2003
    Posts
    6

    Alternative to multipe ELSE IF statements?

    Currently working on a script for indexing a hard drive, and entering data into a "Document Type" column (Column I in this case) based on keywords in the documents. What I currently have works perfectly, but takes forever as it sometimes can be upwards of 10,000 files. Is there an easier way that provides the same results?

    Please Login or Register  to view this content.
    I've changed the names for example purposes, haha.

  2. #2
    Forum Expert Bob Phillips's Avatar
    Join Date
    09-03-2005
    Location
    Wessex
    MS-Off Ver
    Office 2003, 2010, 2013, 2016, 365
    Posts
    3,284

    Re: Alternative to multipe ELSE IF statements?

    Is this any quicker

    Please Login or Register  to view this content.

  3. #3
    Registered User
    Join Date
    05-16-2012
    Location
    Ontario
    MS-Off Ver
    Excel 2003
    Posts
    6

    Re: Alternative to multipe ELSE IF statements?

    I get a "Run-time error 13 Type Mismatch" on the first Case objFile.Name line of that code? I appreciate the help, by the way!

    EDIT: It doesn't appear as though the Select Case statement lets you have multiple "likes" for each case. Dumping it down to a Case each for "*cheese*", "*gouda*", and "*havarti*" works, but having "*Cheese*", "*Gouda*", "*Havarti*" in one Case Like statement doesn't. If that makes sense...I'm fairly new to this.

    Unfortunately, I don't think having a separate Case statement for each keyword will be any faster than having a separate Else If statement, but I'm willing to give it a try.
    Last edited by Winterreise; 05-16-2012 at 02:16 PM.

  4. #4
    Forum Expert Bob Phillips's Avatar
    Join Date
    09-03-2005
    Location
    Wessex
    MS-Off Ver
    Office 2003, 2010, 2013, 2016, 365
    Posts
    3,284

    Re: Alternative to multipe ELSE IF statements?

    I think you are correct on both counts, you cannot use Like in multi-case statements, and it wouldn't be any faster anyway.

    Assuming your source data is on a worksheet, a quicker way might be to add a formula to that sheet to calculate the answer. The formula can probably be applied in one step, and would be much faster than a VBA loop.

  5. #5
    Registered User
    Join Date
    05-16-2012
    Location
    Ontario
    MS-Off Ver
    Excel 2003
    Posts
    6

    Re: Alternative to multipe ELSE IF statements?

    That sounds intriguing...would you happen to know of an example? As I said I'm fairly new to this, and tend to learn best from reading examples. Either way, I'm off to try Googling up some stuff. Thank you!

  6. #6
    Forum Expert Bob Phillips's Avatar
    Join Date
    09-03-2005
    Location
    Wessex
    MS-Off Ver
    Office 2003, 2010, 2013, 2016, 365
    Posts
    3,284

    Re: Alternative to multipe ELSE IF statements?

    Can you post a workbook? I can then knock up a solution based upon your code to date.

  7. #7
    Registered User
    Join Date
    05-16-2012
    Location
    Ontario
    MS-Off Ver
    Excel 2003
    Posts
    6

    Re: Alternative to multipe ELSE IF statements?

    That would be fantastic, and well above anything you have to do! I've attached it...but be warned, as I said I'm new, it's pretty bad to look at, I think. I've removed about half of the Else If statements since just a few gives you the idea!

    Thank you again, I appreciate it!
    Attached Files Attached Files

+ 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