+ Reply to Thread
Results 1 to 6 of 6

".Find" arguments

  1. #1
    Forum Contributor
    Join Date
    02-23-2006
    Location
    Near London, England
    MS-Off Ver
    Office 2003
    Posts
    770

    Question ".Find" arguments

    I have generally used the .Find function in the following form:
    Please Login or Register  to view this content.
    As I figured that I wanted to look at the VALUE of the Excel cell when finding, not the text fo the formula that created that value.

    However today I had a situation where I just could not find a value that I KNEW was there.
    As I hadn't changed much i did a small test to repeat the 'issue'.

    In cell A1 I entered;
    Please Login or Register  to view this content.
    Fitted the column to the data and then used the following code to find it:
    Please Login or Register  to view this content.
    It found it fine.
    I then resized the column and the cell changed to "9.9E+08", ran the macro, and not found.
    I resized it smaller still until the cell changed to "##", ran the macro, and not found.

    I can only take from this that the .Find function when set to xlValues doesn't find the values in the spreadsheet, but actually the values DISPLAYED in the cells, (which now that I've tested it seems to be the same as the behaviour of the 'Find / Replace' dialog.

    Does this mean that every time I do a find and I want the actual value of the cell, (not the displayed value), I should be search for xlFormulas? Do I then also have to test the first character of every found cell to make sure it is not "=", so that I know I have actually found a VALUE rather than a FORMULA ?

    Thanks
    Last edited by Phil_V; 08-03-2009 at 10:44 AM.
    If you find the response helpful please click the scales in the blue bar above and rate it
    If you don't like the response, don't bother with the scales, they are not for you

  2. #2
    Valued Forum Contributor Richard Schollar's Avatar
    Join Date
    05-23-2006
    Location
    Hampshire UK
    MS-Off Ver
    Excel 2002
    Posts
    1,264

    Re: ".Find" arguments

    Hi Phil

    It certainly looks like the Find uses what would be the Text property of the cell (in VBA) rather than the actual value.

    If you know in advance you only want to find cells containing "XX" that are formula cells/are not formula cells, you could use the SpecialCells method to return a range that only contains formulas or values. Alternatively, you could check the HasFormula property of the returned range object to determine if it contained a formula.

    Richard
    Richard Schollar
    Microsoft MVP - Excel

  3. #3
    Forum Guru
    Join Date
    08-26-2007
    Location
    London
    Posts
    4,606

    Re: ".Find" arguments

    Never noticed that. I generally use Formulas rather than Values. As a rule I think it's better practice to specify all parameters.

  4. #4
    Forum Contributor
    Join Date
    02-23-2006
    Location
    Near London, England
    MS-Off Ver
    Office 2003
    Posts
    770

    Re: ".Find" arguments

    Thanks both.


    Stephen, just regarding your comment, am I correct in thinking that even if I DID specify all the arguments it wouldn't effect anything here? (I can't see any of the optional arguments that would effect it?)

    Richard, I think I shall have to start using one of the two methods that you have suggested.

    I may have 987654321 in a cell which is too narrow, (which is the cell I want to find), and also have somewhere else on the sheet =987654321+1 which I do not want to find.
    If I search for xlPart, xlFormulas, and "98765" for example, I will find both cells, so will definitly have to use one of the 2 "make sure it's not a formula" methods you mentioned

  5. #5
    Forum Guru
    Join Date
    08-26-2007
    Location
    London
    Posts
    4,606

    Re: ".Find" arguments

    Phil - yes, I think in this case you are correct to think that. The thinking more generally is that code may not work because (unbeknownst to or forgotten by the coder) some of the settings may have been altered, say directly from the worksheet.

  6. #6
    Forum Contributor
    Join Date
    02-23-2006
    Location
    Near London, England
    MS-Off Ver
    Office 2003
    Posts
    770

    Re: ".Find" arguments

    Aha, I see your point
    I just wanted to make sure I hadn't missed something!

    Cheers

+ 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