Consulting

Results 1 to 5 of 5

Thread: .Find function

  1. #1

    .Find function

    I'm trying to use the .find function on a range in a vba user defined function.
    I've found though the .find does not work in a user defined function for vba on mac osx, even when the same code works on a windows platform.

    It's strange as .find appears to work with sub routines, but with UDFs it causes the function to exit with no error messages

    Has anyone else noticed this and found a solution.

  2. #2
    Mac Moderator VBAX Guru mikerickson's Avatar
    Joined
    May 2007
    Location
    Davis CA
    Posts
    2,778
    I've found that there are several methods that don't work when called from a worksheet, but do work when called from VBA.

    .Find
    .SpecialCells
    .NavagateArrow

    are the ones at the top of my mind.

    In most of the cases, looping will serve as a workaround.

  3. #3
    VBAX Regular
    Joined
    Nov 2007
    Posts
    31
    Location
    I am also trying to use the .find method and running into problems. Seems to work on Windows fine, but will not work on Mac. It doesn't seem as if the libraries on the mac have this built in. Am I missing something? Is there another way to use some sort of VBA .find method to search through a range of cells and assigning the fund value to a variable or the offset to the found value to that variable

  4. #4
    Mac Moderator VBAX Guru mikerickson's Avatar
    Joined
    May 2007
    Location
    Davis CA
    Posts
    2,778
    Rather than
    Set foundCell = someRange.Find("search term")
    you could use
    Set foundCell = Nothing
    For each oneCell in SomeRange
        If oneCell.Value = "search term" Then Set foundCell = oneCell: Exit Sub
    Next oneCell
    BTW, the .Find method of a Range works fine on my Mac when used in VBA subs. Just not when in a UDF that is called by a worksheet formula.

  5. #5
    VBAX Regular
    Joined
    Nov 2007
    Posts
    31
    Location
    Quote Originally Posted by mikerickson View Post
    Rather than
    Set foundCell = someRange.Find("search term")
    you could use
    Set foundCell = Nothing
    For each oneCell in SomeRange
        If oneCell.Value = "search term" Then Set foundCell = oneCell: Exit Sub
    Next oneCell
    BTW, the .Find method of a Range works fine on my Mac when used in VBA subs. Just not when in a UDF that is called by a worksheet formula.

    Thanks for the reply...Yes, I used a for each loop to get it to work and yes it is a UDF called from a worksheet formula.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •