+ Reply to Thread
Results 1 to 15 of 15

Instr function that uses various characters as 1

  1. #1
    Forum Contributor
    Join Date
    06-29-2005
    Posts
    201

    Instr function that uses various characters as 1

    Hi all

    I am trying to write a function that recalculates given times to points (as used in speedskating)
    The times are filled in by a number of people, which each use their own methode of dviding minutes from seconds (and 1/100 of a sec)

    I found out how to see the difference between times that look like 1.11.11 and 11.11 etc

    What I can't figure out is how to use that same method in an InStr function. Most of the times I get an error message #Value or something that has that format, sometimes all I get is a 0

    I have made a demo that hopefully makes better sense than this rather clumpsy description

    Is there a way to make this work?

    All help appreciated

    Hein
    Attached Files Attached Files
    Last edited by Hein; 04-14-2014 at 03:48 PM.

  2. #2
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: Instr function that uses various characters as 1

    Hi,

    I don't understand what you are trying to do and what your various values represent. Neither can I see what 'TimeToPoints' is other than perhaps an as yet unwritten function.

    Would you manually add some example results covering all permutations and explain how you arrive at the results.
    Richard Buttrey

    RIP - d. 06/10/2022

    If any of the responses have helped then please consider rating them by clicking the small star icon below the post.

  3. #3
    Forum Contributor
    Join Date
    06-29-2005
    Posts
    201

    Re: Instr function that uses various characters as 1

    Hi Richard

    Thank you for responding

    What I am trying to do is to get information what the position is from one of the characters (captured in Chars). When I know this I can start calculating using the value in front of this position

    The 1st function I have added is to show that the method of using the chars works. Therefore I have created each possible variation and if the "code" understands it right it will respond with "Check"

    The 2nd function is the actual formula I want to use (or at least part of it).

    Let me give you a few examples

    If the VellValue is .... than the outcome should be ...
    1.23.45 ..... 1
    23-45-38 .... 23
    9:55:85 ....... 9

    I hope this info is useful

    Hein

  4. #4
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    46,389

    Re: Instr function that uses various characters as 1

    I thought you were trying to convert the strings to times, well, the same time in the example.

    Try this:

    Please Login or Register  to view this content.

    I'm sure there are alternatives using Regular Expressions but that is one of my weak areas.

    If the string cannot be evaluated as a time (by Excel), you can process it character by character. If Excel recognises it as a valid time, it will be treated as a fractional number so you won't be able to test for specific characters, nor, I guess, do you need to.

    Regards, TMS

    Regards, TMS
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


  5. #5
    Forum Contributor
    Join Date
    06-29-2005
    Posts
    201

    Re: Instr function that uses various characters as 1

    Thank you TMS for the trouble you went through to make this code.
    BTW I am sorry for my late respons, sometimes urgent matters happen.

    Your code doesn't bring me where I would like to go.
    What you do is to recalculate each value to a time, which is the same as the original input, except that your "arrays" are all replaced by a :

    What I would like is to capture all numbers that are in front of the characters. I my 2nd thread these are the 1, 23 and 9

    Can that be done? (If an array in the code is needed then, of course, I am OK with that).

    Hein

  6. #6
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: Instr function that uses various characters as 1

    Hi,

    Does this one help?

    Please Login or Register  to view this content.

  7. #7
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    46,389

    Re: Instr function that uses various characters as 1

    Cancel that: misread the requirement

  8. #8
    Forum Contributor
    Join Date
    06-29-2005
    Posts
    201

    Re: Instr function that uses various characters as 1

    Richard: 1 word: BRILLIANT!

    This is exactly what I was looking for.
    At first there was 1 version that gave a little problem: 1:11:11 (which is, as you know, the time-notation)
    Changing the cell properties to text solved that problem.

    I have also tried out a few combinations (using different arrays in 1 cell) and most, but not, all work as required (however, these are combinations that are not likely to occur.)

    Now I can write the rest of the function in a few lines, instead of having to work out all possible

    Thanks again, Thumbs Up!!
    Hein

  9. #9
    Forum Contributor
    Join Date
    06-29-2005
    Posts
    201

    Re: Instr function that uses various characters as 1

    Thank you TMS

    As you may have seen the question has been solved in the meantime

    Thanks for your trouble
    Hein

  10. #10
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    46,389

    Re: Instr function that uses various characters as 1

    OK, for my benefit anyway, my reworked solution.

    Please Login or Register  to view this content.

    The only concern that I have is that some of your entries may be interpreted by Excel as a time. If that is the case, the content of the cell will be a numeric value representing a fraction of a day. You may not get the value you expect under those circumstances.


    Regards, TMS

  11. #11
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    46,389

    Re: Instr function that uses various characters as 1

    You're welcome. Thanks for the rep.



    Please note that my solution produces different results to Richard's. You may want to review the attached workbook and tweak one of the solutions to better meet your needs.


    Regards, TMS



    If you are satisfied with the solution(s) provided, please mark your thread as Solved.


    New quick method:
    Select Thread Tools-> Mark thread as Solved. To undo, select Thread Tools-> Mark thread as Unsolved.

    Or you can use this way:

    How to mark a thread Solved
    Go to the first post
    Click edit
    Click Go Advanced
    Just below the word Title you will see a dropdown with the word No prefix.
    Change to Solved
    Click Save


    You may also want to consider thanking those people who helped you by clicking on the little star at the bottom left of their reply to your question.
    Attached Files Attached Files

  12. #12
    Forum Contributor
    Join Date
    06-29-2005
    Posts
    201

    Re: Instr function that uses various characters as 1

    Hi TMS

    Luckily I saw your thread (just before I wanted to set it to solved)

    Your code is (for me at least) very different to Richard's. But both work. This means I have some studying to do to !

    Your remark is right about Excel's interpretation that some cells are a time (and will be hanged to a fraction of a day)
    This is in my use very annoying as it keeps popping up. Just as it is very anoying to work with conditional formatting that seems to have a mind of its own (if only I could turn this "thinking with the user" off)

    Anyway, tomorrow I have a nice day ahead of making the function and add a few more things (which I have already found out how to do)

    Thanks again
    Hein

  13. #13
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    46,389

    Re: Instr function that uses various characters as 1

    A variation on a theme ... something like my original approach but building on the one I listed above:


    Please Login or Register  to view this content.

    This also copes with times but, if the first digit is 0 it drops it. So, 9:56:25, which may be interpreted as 09:56:25, will return 9, rather than 0 or 09. 19:56:25 will return 19:56:25 will return 19 regardless of whether it is seen as a string or a time.


    Regards, TMS

  14. #14
    Forum Contributor
    Join Date
    06-29-2005
    Posts
    201

    Re: Instr function that uses various characters as 1

    you must find this a challenging question I think
    Variations keep popping up
    Feel free to do so, it is already late for me (in the Netherlands) but tomorrow it has my full attention

    Thanks again, much appreciated
    Hein

    PS
    if 09 becomes 9 is no problem for the remainder of the code

  15. #15
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    46,389

    Re: Instr function that uses various characters as 1

    No more variations, I'm done

+ 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. [SOLVED] InStr Function
    By msolari in forum Excel Programming / VBA / Macros
    Replies: 12
    Last Post: 12-18-2012, 01:52 PM
  2. Instr() function
    By Lifeseeker in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 12-20-2011, 03:57 PM
  3. Replies: 3
    Last Post: 02-25-2011, 01:58 PM
  4. Instr Function
    By max57 in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 05-01-2010, 03:58 PM
  5. [SOLVED] InStr Function
    By zoot in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 06-04-2006, 10:55 PM

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