+ Reply to Thread
Results 1 to 5 of 5

Search Box In Excel

Hybrid View

  1. #1
    Registered User
    Join Date
    01-06-2010
    Location
    Lancashire
    MS-Off Ver
    Excel 2000
    Posts
    4

    Smile Search Box In Excel

    Can anyone help?

    I'm try to create a macro that searches the whole of a spreadsheet and finds any records that match.....

    I've managed to find this...

    Sub myfind()
    Dim Message, Title, Default, SearchString
    Message = "Enter Permit Number/Car Registration Number" ' Set prompt.
    Title = "Find Permit/Registration Number" ' Set title.
    Default = "" ' Set default.
    ' Display message, title, and default value.
    SearchString = InputBox(Message, Title, Default)
    
    'SearchString = "Rob"
    Set S = Sheets.Application
    For Each S In Application.Sheets
    With S.Range("A1:IV65536")
    Set F = .Find(SearchString, MatchCase:=True, LookAt:=xlWhole, LookIn:=xlValues)
    If F Is Nothing Then
    Else
    Location = F.Address
    S.Select
    Range(Location).Select
    Exit For
    End If
    End With
    Next S
    End Sub
    But what I really want it to do is search and display only the records that match and give an error message if nothing is found, anyone?
    Last edited by teylyn; 01-06-2010 at 07:59 AM. Reason: added code tags

  2. #2
    Forum Expert teylyn's Avatar
    Join Date
    10-28-2008
    Location
    New Zealand
    MS-Off Ver
    Excel 365 Insider Fast
    Posts
    11,372

    Re: Search Box In Excel

    Hi flipflop,

    welcome to the forum. Please take a good look at the forum rules, especially with regards to posting code and posting a question in only one forum.

    I've added code tags to this post and locked your duplicate post.

    I expect you to stick to the rules of this forum from now on.

    cheers.

  3. #3
    Forum Expert pike's Avatar
    Join Date
    12-11-2005
    Location
    Alstonville, Australia
    MS-Off Ver
    2016
    Posts
    5,342

    Re: Search Box In Excel

    Hi flipflop
    Really good attempt try playing around with this example
    Sub ptest()
    searchstring = Sheets("Sheet1").Range("A1")
    Set LookInR = Sheets("Sheet2").Range("A1").CurrentRegion
    With LookInR
               Set FoundOne = .Find(What:=searchstring, lookat:=xlPart)
            If Not FoundOne Is Nothing Then
                fAddress = FoundOne.Address
                Do
                    Range(fAddress).Activate
                  Loop While FoundOne.Address <> fAddress
            End If
      
    End With
    End Sub
    If the solution helped please donate to RSPCA

    Site worth visiting: Rabbitohs

  4. #4
    Registered User
    Join Date
    01-06-2010
    Location
    Lancashire
    MS-Off Ver
    Excel 2000
    Posts
    4

    Re: Search Box In Excel

    Thanks for your help.

    Sorry I'm not very good with things like this trying to learn from scratch...

    Is that code to replace all of my code or just part of it?

    I'm trying to assign the macro to a button so when you click on it it brings up the search box, you then enter what you want to find and clikc on ok. It will then bring up all records that match.

    Sorry again

  5. #5
    Forum Expert pike's Avatar
    Join Date
    12-11-2005
    Location
    Alstonville, Australia
    MS-Off Ver
    2016
    Posts
    5,342

    Re: Search Box In Excel

    Hi flipflop
    try this
    Message = "Enter Permit Number/Car Registration Number" ' Set prompt.
    Title = "Find Permit/Registration Number" ' Set title.
    Default = "" ' Set default.
    ' Display message, title, and default value.
    SearchString = InputBox(Message, Title, Default)
    Set LookInR = Sheets("Sheet1").Range("A1").CurrentRegion
    With LookInR
               Set FoundOne = .Find(What:=searchstring, lookat:=xlPart)
            If Not FoundOne Is Nothing Then
                fAddress = FoundOne.Address
                Do
                    Range(fAddress).Activate
                  Loop While FoundOne.Address <> fAddress
            End If
      
    End With
    End Sub

+ 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