+ Reply to Thread
Results 1 to 4 of 4

Cells.find and .findnext

Hybrid View

Buzzaro Cells.find and .findnext 08-20-2007, 07:48 AM
royUK The VBA help file example is... 08-20-2007, 07:49 AM
Buzzaro With... 08-20-2007, 07:59 AM
mudraker When working with the active... 08-20-2007, 08:29 AM
  1. #1
    Registered User
    Join Date
    08-20-2007
    Posts
    20

    Cells.find and .findnext

    Hi guys, im very new to VBA and have been trying to put together a macro. Ive been trying to use
    Cells.Find(what:="Cost Cde", After:=ActiveCell, LookIn:=xlValues, LookAt:= _
           xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=False _
           , SearchFormat:=False).Activate
    with .findnext but keep getting a variety of errors. Is there a way to use these together or do I need something else altogther?
    Thanks for any help

  2. #2
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200
    The VBA help file example is good.
    Hope that helps.

    RoyUK
    --------
    For Excel Tips & Solutions, free examples and tutorials why not check out my web site

    Free DataBaseForm example

  3. #3
    Registered User
    Join Date
    08-20-2007
    Posts
    20
    Quote Originally Posted by royUK
    The VBA help file example is good.
    With Worksheets(1).Range("a1:a500")
        Set c = .Find(2, lookin:=xlValues)
        If Not c Is Nothing Then
            firstAddress = c.Address
            Do
                c.Value = 5
                Set c = .FindNext(c)
            Loop While Not c Is Nothing And c.Address <> firstAddress
        End If
    End With
    Ive looked at that, but Im very new so theres a couple things that are different than the method ive posted that look different that im not sure about.
    Worksheets(1).Range("a1:a500")
    I would like to search the entire active worksheet as opposed to a specified range and also I tried doing the select worksheet thing but I dont know which worksheet in the workbook the macro is going to be run on, so i would just like it run on the active worksheet. Ive tried adapting that syntax to use the .find method ive posted above and I cant seem to get it to work.

  4. #4
    Valued Forum Contributor mudraker's Avatar
    Join Date
    11-10-2003
    Location
    Melbourne, Australia
    Posts
    3,983
    When working with the active worksheet you do not need to use worksheets(1) in the code
    With Cells
        Set c = .Find(2, LookIn:=xlValues)
        If Not c Is Nothing Then
            firstAddress = c.Address
            Do
                c.Value = 5
                Set c = .FindNext(c)
            Loop While Not c Is Nothing And c.Address <> firstAddress
        End If
    End With
    As the above example finds 2 and replaces that with 5 you could use
    Cells.Replace What:="2", Replacement:="5", LookAt:=xlWhole, SearchOrder _
            :=xlByRows, MatchCase:=False, SearchFormat:=False, ReplaceFormat:=False
    Please Read Forum Rules Before Posting
    Wrap VBA code by selecting the code and clicking the # icon or Read This
    How To Cross Post politely

    Top Excel links for beginners to Experts

    If you are pleased with a member's answer then use the Scales icon to rate it
    If my reply has assisted or failed to assist you I welcome your Feedback.

+ 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