+ Reply to Thread
Results 1 to 5 of 5

Incorrect usage of VBA WSfunction

  1. #1
    Jim May
    Guest

    Incorrect usage of VBA WSfunction


    ..... Omission of lines
    str1 = Right(Target.Formula, Len(Target.Formula) - 1)
    If WorksheetFunction.Find("!", str1) = Err Then Exit Sub << Not Right !!

    line 2 above tests for - If the formula str1 DOES NOT refer to another Sheet
    (with !)
    then exit Sub

    But what is (Right)?

    TIA,

    Jim



  2. #2
    Dave Peterson
    Guest

    Re: Incorrect usage of VBA WSfunction

    Look at InStr in VBA's help.



    Jim May wrote:
    >
    > .... Omission of lines
    > str1 = Right(Target.Formula, Len(Target.Formula) - 1)
    > If WorksheetFunction.Find("!", str1) = Err Then Exit Sub << Not Right !!
    >
    > line 2 above tests for - If the formula str1 DOES NOT refer to another Sheet
    > (with !)
    > then exit Sub
    >
    > But what is (Right)?
    >
    > TIA,
    >
    > Jim


    --

    Dave Peterson

  3. #3
    Les
    Guest

    RE: Incorrect usage of VBA WSfunction

    Since you are running in VBA, use the INSTR function to search for "!"

    i.e.
    If Target.Formula <> "" Then
    str1 = Right(Target.Formula, Len(Target.Formula) - 1)
    If InStr(str1, "!") = 0 Then Exit Sub
    End If

    Please not that "!" does not ensure the formula refers to a separate
    worksheet, it could very well refer to the active worksheet.

    --
    Les Torchia-Wells


    "Jim May" wrote:

    >
    > .... Omission of lines
    > str1 = Right(Target.Formula, Len(Target.Formula) - 1)
    > If WorksheetFunction.Find("!", str1) = Err Then Exit Sub << Not Right !!
    >
    > line 2 above tests for - If the formula str1 DOES NOT refer to another Sheet
    > (with !)
    > then exit Sub
    >
    > But what is (Right)?
    >
    > TIA,
    >
    > Jim
    >
    >


  4. #4
    Tom Ogilvy
    Guest

    RE: Incorrect usage of VBA WSfunction

    iserror test for an error, but use the vba Instr for this

    If Instr(1,str1,"!",vbTextcompare) = 0 Then Exit Sub

    --
    Regards,
    Tom Ogilvy


    "Jim May" wrote:

    >
    > .... Omission of lines
    > str1 = Right(Target.Formula, Len(Target.Formula) - 1)
    > If WorksheetFunction.Find("!", str1) = Err Then Exit Sub << Not Right !!
    >
    > line 2 above tests for - If the formula str1 DOES NOT refer to another Sheet
    > (with !)
    > then exit Sub
    >
    > But what is (Right)?
    >
    > TIA,
    >
    > Jim
    >
    >


  5. #5
    Jim May
    Guest

    RE: Incorrect usage of VBA WSfunction

    Got it !!
    Tks,
    Jim

    "Tom Ogilvy" wrote:

    > iserror test for an error, but use the vba Instr for this
    >
    > If Instr(1,str1,"!",vbTextcompare) = 0 Then Exit Sub
    >
    > --
    > Regards,
    > Tom Ogilvy
    >
    >
    > "Jim May" wrote:
    >
    > >
    > > .... Omission of lines
    > > str1 = Right(Target.Formula, Len(Target.Formula) - 1)
    > > If WorksheetFunction.Find("!", str1) = Err Then Exit Sub << Not Right !!
    > >
    > > line 2 above tests for - If the formula str1 DOES NOT refer to another Sheet
    > > (with !)
    > > then exit Sub
    > >
    > > But what is (Right)?
    > >
    > > TIA,
    > >
    > > Jim
    > >
    > >


+ 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