+ Reply to Thread
Results 1 to 4 of 4

how to execute a function only if it's possible?

  1. #1
    Registered User
    Join Date
    01-27-2011
    Location
    Brazil
    MS-Off Ver
    Excel 2007
    Posts
    75

    how to execute a function only if it's possible?

    For example, if we write:
    Please Login or Register  to view this content.
    If the string does't have "-", a error occurs. So, how can we call a function just it is possible?

    In my case, I use a ".find()" to find some words and copy the contents in front of them. Somethimes, I copy numbers (OK); however, sometimes I copy numbers in the following ways:
    a. [15]
    b. 14 [16]
    c. 10 - 20
    I use "If IsNumeric(number)" to see if it's not numeric and and if it needs to be fixed:
    Please Login or Register  to view this content.
    It was working, but I don't know how to solve when appears the kind b: "14 [16]". Because it enters to the last "else" and, how it doesn't has "-", so the program stops.
    Last edited by marlonsaveri; 03-09-2011 at 11:23 AM.

  2. #2
    Forum Guru (RIP) Marcol's Avatar
    Join Date
    12-23-2009
    Location
    Fife, Scotland
    MS-Off Ver
    Excel '97 & 2003/7
    Posts
    7,216

    Re: how to execute a function only if it's possible?

    Try adding your other conditions to this
    Please Login or Register  to view this content.

    Hope this helps
    If you need any more information, please feel free to ask.

    However,If this takes care of your needs, please select Thread Tools from menu above and set this topic to SOLVED. It helps everybody! ....

    Also
    اس کی مدد کرتا ہے اگر
    شکریہ کہنے کے لئے سٹار کلک کریں
    If you are satisfied by any members response to your problem please consider using the small Star icon bottom left of their post to show your appreciation.

  3. #3
    Registered User
    Join Date
    01-27-2011
    Location
    Brazil
    MS-Off Ver
    Excel 2007
    Posts
    75

    Re: how to execute a function only if it's possible?

    Thanks so much.
    InStr() discover if a string is inside another?!

    I'll let it here if someone else have the some answer.

    From: http://www.techonthenet.com/excel/formulas/instr.php

    MS Excel: InStr Function (VBA only)

    --------------------------------------------------------------------------------

    In Excel, the InStr function returns the position of the first occurrence of a string in another string.

    The syntax for the InStr function is:

    InStr( [start], string_being_searched, string2, [compare] )

    start is optional. It is the starting position for the search. If this parameter is omitted, the search will begin at position 1.

    string_being_searched is the string that will be searched.

    string2 is the string to search for.

    compare is optional. This is the type of comparison to perform. The valid choices are:

    VBA Constant Value Explanation
    vbUseCompareOption -1 Uses option compare.
    vbBinaryCompare 0 Binary comparison
    vbTextCompare 1 Textual comparison
    vbDatabaseCompare 2 Comparison based on your database.



    Applies To:

    •Excel 2007, Excel 2003, Excel XP, Excel 2000


    For example:

    InStr(1, "Tech on the Net", "the") would return 9.
    InStr("Tech on the Net", "the") would return 9.
    InStr(10, "Tech on the Net", "t") would return 15.



    VBA Code
    The InStr function can only be used in VBA code. For example:

    Dim LPosition As Integer

    LPosition = InStr(10, "Tech on the Net", "t")

    In this example, the variable called LPosition would now contain the value 15.


    So, if it's >0, than it returns something; therefore, there's a "-" in the string!

  4. #4
    Forum Guru (RIP) Marcol's Avatar
    Join Date
    12-23-2009
    Location
    Fife, Scotland
    MS-Off Ver
    Excel '97 & 2003/7
    Posts
    7,216

    Re: how to execute a function only if it's possible?

    Yes.
    If you search for a certain string within a given string, if the "find what" string you want to find is found then a number greater than zero will be returned.

    This is the position of the first character of your "find what" string within the target string.

    If your "find what" string is not found, then 0 (zero) will be returned.

+ 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