+ Reply to Thread
Results 1 to 5 of 5

Find Function Parameters work if recorded but not if written?

Hybrid View

  1. #1
    Forum Contributor noboffinme's Avatar
    Join Date
    08-29-2013
    Location
    Melbourne, Australia
    MS-Off Ver
    Excel 2003/7/10/13/16/19
    Posts
    1,071

    Find Function Parameters work if recorded but not if written?

    Hi Forum,

    I'm writing a Macro to search through several Worksheets for a Value.
    I've recorded the code using the Find Function & changing some of the parameters to get more exact results.
    Example, the values I'm searching for are exactly what should appear in a Cell & be in the same case, so I've made those changes in the Find Dialogue box when I recorded the Macro.
    My issue is that when I try to paste the same Macro the parts that cause errors are the 'LookAt :=Whole' and the 'MatchCase:=True' in the Find Parameters?

    Here's my code & the data I'm using is a worksheet where the Value 'EMP' occurs randomly.

    Either one will throw an error, & I wondered if anyone knows why & also how to fix this?

    Thanks Peter

    Sub find_all_emps()
    
        Sheets("CHTAB").Select
        Range("A1").Select
        Selection.CurrentRegion.Select
        Selection.find(What:="EMP", After:=ActiveCell, LookIn:=xlValues, _
            LookAt:=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
            MatchCase:=True, SearchFormat:=False).Activate
       End Sub
    Attached Images Attached Images
    Remember you are unique, like everyone else

  2. #2
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,671

    Re: Find Function Parameters work if recorded but not if written?

    It occurs when Find method has no result.
    Sub find_all_emps()
        Dim r As Range
        Sheets("CHTAB").Select
        Range("A1").Select
        Selection.CurrentRegion.Select
        Set r = Selection.find(What:="EMP", After:=ActiveCell, LookIn:=xlValues, _
            LookAt:=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
            MatchCase:=True, SearchFormat:=False)
        If Not r Is Nothing Then r.Select
       End Sub

  3. #3
    Forum Contributor noboffinme's Avatar
    Join Date
    08-29-2013
    Location
    Melbourne, Australia
    MS-Off Ver
    Excel 2003/7/10/13/16/19
    Posts
    1,071

    Re: Find Function Parameters work if recorded but not if written?

    Thanks jindon, works fine.

  4. #4
    Forum Guru MarvinP's Avatar
    Join Date
    07-23-2010
    Location
    Woodinville, WA
    MS-Off Ver
    Office 365
    Posts
    16,169

    Re: Find Function Parameters work if recorded but not if written?

    Hi Peter,

    What would this macro do?
    Sub Macro1()
    
        Cells.Find(What:="EMP", After:=ActiveCell, LookIn:=xlValues, LookAt:= _
            xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=True _
            , SearchFormat:=False).Activate
    End Sub
    Perhaps your Selection doesn't go to the cell you want??
    One test is worth a thousand opinions.
    Click the * Add Reputation below to say thanks.

  5. #5
    Forum Contributor noboffinme's Avatar
    Join Date
    08-29-2013
    Location
    Melbourne, Australia
    MS-Off Ver
    Excel 2003/7/10/13/16/19
    Posts
    1,071

    Re: Find Function Parameters work if recorded but not if written?

    Thanks MarvinP, yours also works fine, Thank you.

+ 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] Shortening the parameters of in a recorded macro
    By ImranBhatti in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 09-25-2018, 09:14 AM
  2. Recorded macro - doesn`t work
    By Bandini in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 09-12-2014, 02:20 AM
  3. How to add parameters to the find function vba
    By jakeembx in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 01-07-2014, 09:13 AM
  4. add in the parameters to the Find function to only find an exact match.
    By jakeembx in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 01-07-2014, 08:57 AM
  5. Help! The recorded Macro does not work for the highlighted
    By lans_bazx in forum Excel Programming / VBA / Macros
    Replies: 30
    Last Post: 09-19-2012, 06:59 PM
  6. Recorded Macro Does Not Work
    By TheColorLavender in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 06-05-2012, 01:56 AM
  7. How to alter a recorded macro to work better
    By antonymiller in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 07-14-2009, 02:53 AM

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