+ Reply to Thread
Results 1 to 13 of 13

Find illegal file names

  1. #1
    Forum Expert
    Join Date
    09-01-2012
    Location
    Norway
    MS-Off Ver
    Office 365
    Posts
    2,885

    Find illegal file names

    Hello

    I have a column of strings. These strings will be used to create file names and therefor must not contain < > : " / \ | ? *.
    Can a formula be made to check if any of the strings contain any of these characters?
    <----- If you were helped by my posts you can say "Thank you" by clicking the star symbol down to the left

    If the problem is solved, finish of the thread by clicking SOLVED under Thread Tools
    I don't wish to leave you with no answer, yet I sometimes miss posts. If you feel I forgot you, remind me with a PM or just bump the thread.

  2. #2
    Forum Contributor dogberry's Avatar
    Join Date
    07-15-2012
    Location
    Wales, UK
    MS-Off Ver
    Excel 2010
    Posts
    624

    Re: Find illegal file names

    Hi

    Would it not be quicker and easier to use find replace

    Chris
    Click my star if I helped Thanks

  3. #3
    Registered User
    Join Date
    11-26-2012
    Location
    Kitchener, Ontario, Canada
    MS-Off Ver
    Excel 2010
    Posts
    82

    Re: Find illegal file names

    Try this function which return "True" if any of the invalid character exists in function argument "FileName"
    Please Login or Register  to view this content.


    _________________________________
    aelgadi

    >>> If I helped, Don't forget to add to my reputation (click on the star at left bottom of the post)
    >>> If satisfied with a solution, don't forget to mark threads as "Solved" (Thread Tools->Mark thread as Solved)
    Last edited by aelgadi; 12-03-2012 at 11:04 PM.

  4. #4
    Forum Expert tigeravatar's Avatar
    Join Date
    03-25-2011
    Location
    Colorado, USA
    MS-Off Ver
    Excel 2003 - 2013
    Posts
    5,361

    Re: Find illegal file names

    Jacc,

    Attached is an example workbook based on the criteria you described.
    Column A has had this conditional format formula applied to it:
    Please Login or Register  to view this content.
    All cells in column A with an illegal character are now red highlighted. Would something like that work?

    As a side note, I agree with dogberry's suggestion also. A find/replace should work just fine.
    Attached Files Attached Files
    Hope that helps,
    ~tigeravatar

    Forum Rules: How to use code tags, mark a thread solved, and keep yourself out of trouble

  5. #5
    Forum Expert
    Join Date
    09-01-2012
    Location
    Norway
    MS-Off Ver
    Office 365
    Posts
    2,885

    Re: Find illegal file names

    Thanks for the replies guys!
    Dogberry, I agree with you, for many purposes the f&r is effective and fast. What I failed to mention was that this is for an application that others will use. It's up to the user to put the correct name on things as these names will also be used for pictures and so on. I just want to warn them. There is nothing to replace with and if I replace with nothing I could end up with duplicates. Hmm... I do already have a duplicate check...

    aelgade, your function looks nice and clean. However, my dataset is about 1000 to 2000 lines and I believe a VBA function would struggle to keep up the pace with the Excel built in functions. I believe there is an InStr function in VBA that might speed things up a bit, though.

    tigeravatar, your function seems to do the trick. I just need a moment here to figure out what is going on (as always with Excel functions ). In the process I will turn it into a regular function in an extra column. The reason is that I read that CF is volatile and will recalc for any reason. My application is slow as it is, so I am a little paranoid with anything taking time . Hold on, that ROW($1:$9) can't be right, the data is all the way to row 18. Or?

    I appreciate your inputs, all different angles covered.

  6. #6
    Forum Expert
    Join Date
    09-01-2012
    Location
    Norway
    MS-Off Ver
    Office 365
    Posts
    2,885

    Re: Find illegal file names

    Quote Originally Posted by Jacc View Post
    Hold on, that ROW($1:$9) can't be right, the data is all the way to row 18. Or?
    Seems that it is supposed to be ROW($1:$10) as their are 10 illegal characters.
    I tried to dissect the formula into several columns to study it but that just don't work. I guess SUMPRODUCT turns it into an array formula but even made as array formulas the parts don't work alone. How does this thing work?

  7. #7
    Forum Expert
    Join Date
    09-01-2012
    Location
    Norway
    MS-Off Ver
    Office 365
    Posts
    2,885

    Re: Find illegal file names

    Sorry, 9 is correct. There was an error and I solved it by changing 9 to 10. Turned out the error was related to having A2 in one place and A1 in the other, or something like that.

    I have the formula figured out now.

  8. #8
    Forum Expert
    Join Date
    09-01-2012
    Location
    Norway
    MS-Off Ver
    Office 365
    Posts
    2,885

    Re: Find illegal file names

    It works like a charm and it's pretty fast it seems. I made a test on 1000 rows and it was almost instant.
    Thanks tigeravatar! It's an impressive formula.
    No star for you now, it seems you got the last one.

    The formula would have made my day if it wasn't for this: http://www.excelforum.com/excel-gene...to-unhide.html

  9. #9
    Forum Expert tigeravatar's Avatar
    Join Date
    03-25-2011
    Location
    Colorado, USA
    MS-Off Ver
    Excel 2003 - 2013
    Posts
    5,361

    Re: Find illegal file names

    You're very welcome And yes, you're correct the row ($1:$9) is because there are 9 illegal characters to check for.

  10. #10
    Forum Expert
    Join Date
    09-01-2012
    Location
    Norway
    MS-Off Ver
    Office 365
    Posts
    2,885

    Re: Find illegal file names

    Well, it didn't end so well as you can read here: http://www.excelforum.com/excel-gene...to-unhide.html
    Formula is brilliant and I can't recreate the error in another workbook with another table. However, it can't be used in that very table because of some weird Excel bug.

  11. #11
    Forum Expert
    Join Date
    09-01-2012
    Location
    Norway
    MS-Off Ver
    Office 365
    Posts
    2,885

    Re: Find illegal file names

    In theory it seems that aelgadi's UDF would be faster if it used InStr instead for FileNames longer than 9 characters. I have up to 26 characters.
    In real life I'm not gonna bother, I just implemented it and it takes about a second for 1000 lines.
    Today's star goes to Kitchener, Ontario!

  12. #12
    Registered User
    Join Date
    11-26-2012
    Location
    Kitchener, Ontario, Canada
    MS-Off Ver
    Excel 2010
    Posts
    82

    Re: Find illegal file names

    Hello Jacc,

    Tank you Jacc for comming back to me. I know for me there is no more star from you but I'm here to help that's all. You keep mentioning about Instr built-in function so I did it for if this what you did expect.
    If you try this please let me know let me know whether it's faster or slower....
    Thanks again

    Please Login or Register  to view this content.
    aelgadi

    >>> If satisfied with a solution, don't forget to mark threads as "Solved" (Thread Tools->Mark thread as Solved)
    Last edited by aelgadi; 12-05-2012 at 01:45 PM. Reason: Spelling and rephrasing

  13. #13
    Forum Expert
    Join Date
    09-01-2012
    Location
    Norway
    MS-Off Ver
    Office 365
    Posts
    2,885

    Re: Find illegal file names

    Thanks! Since I suggested it I had to do some testing.

    Tried with a string length of 141 and 10 000 rows, no illegal characters. CaseSel around 1.2 s, Instring around 0.35 s.
    Tried again with a string length of 3, CaseSel around 0.3 s, Instring around 0.25 s.
    Booth of them are far quicker than I expected a UDF to be. Are UDF's faster now then in Excel 2003, or is it all the computer? Who knows.

    Since I only have about 1000 lines I'm gonna go with CaseSel cause the code looks better.
    Last edited by Jacc; 12-05-2012 at 03:45 PM. Reason: added "no illegal characters"

+ 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