+ Reply to Thread
Results 1 to 7 of 7

Search sheet and display results

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    06-18-2008
    Posts
    123

    Search sheet and display results

    Hi all, hope everyone's well.

    I've got a worksheet I need help with. Its a list of companies in column A, and their address etc in column B.

    I have added a search button and inputbox by "borrowing" it from another sheet I found, but I cant get it to work properly. I'm not very good with VBA to be honest, I only know some basic things.

    I've attached the sheet so hopefully someone will have some ideas! I want to input the name of a company, then bring up the details for all the matching companies. I'm not 100% sure what I want it to look like etc, as long as it does the job that's fine.

    Thanks a lot,

    Tony
    Attached Files Attached Files

  2. #2
    Forum Guru
    Join Date
    08-26-2007
    Location
    London
    Posts
    4,606
    Here's one approach, which puts the results on sheet2.
    Private Sub CommandButton1_Click()
        
        Dim ManufacturerNum
        Dim Details As Double
        ManufacturerNum = InputBox("Enter the manufacturer")
        With Sheets("List")
            Sheet2.UsedRange.Clear
            .AutoFilterMode = False
            .Range("A1").AutoFilter field:=1, Criteria1:=ManufacturerNum
            .AutoFilter.Range.Copy Sheet2.Range("A1")
            .AutoFilterMode = False
        End With
        
    End Sub

  3. #3
    Forum Guru
    Join Date
    08-05-2004
    Location
    NJ
    MS-Off Ver
    365
    Posts
    13,582
    I like Stephen's approach. I added the following line after "End With" to modify the sheet2 name
        Sheet2.Name = ManufacturerNum
    ChemistB
    My 2?

    substitute commas with semi-colons if your region settings requires
    Don't forget to mark threads as "Solved" (Edit First post>Advanced>Change Prefix)
    If I helped, Don't forget to add to my reputation (click on the little star at bottom of this post)

    Forum Rules: How to use code tags, mark a thread solved, and keep yourself out of trouble

  4. #4
    Forum Contributor
    Join Date
    06-18-2008
    Posts
    123
    Guys your all legend! Worked a treat

  5. #5
    Forum Contributor
    Join Date
    06-18-2008
    Posts
    123
    Sorry guys, one last thing.

    If I click the Cancel button, I get the debug box. I've inserted a line of code that fixes this and just closes the box, however, sheet 2 no longer changes name?

    This is what I've done:

    Private Sub CommandButton1_Click()
        
        Dim ManufacturerNum
        Dim Details As Double
        ManufacturerNum = InputBox("Enter the manufacturer")
        With Sheets("List")
            Sheet2.UsedRange.Clear
            .AutoFilterMode = False
            .Range("A1").AutoFilter field:=1, Criteria1:=ManufacturerNum
            .AutoFilter.Range.Copy Sheet2.Range("A1")
            .AutoFilterMode = False
            If InputRange = False Then Exit Sub
        End With
        Sheet2.Name = ManufacturerNum
        
    End Sub
    Any ideas?

  6. #6
    Forum Guru
    Join Date
    08-26-2007
    Location
    London
    Posts
    4,606
    Do you mean you want sheet2 to revert to "Sheet2"? If so, try this:
    Private Sub CommandButton1_Click()
        
        Dim ManufacturerNum
        Dim Details As Double
        ManufacturerNum = InputBox("Enter the manufacturer")
        If ManufacturerNum = Cancel Then
            Sheet2.Name = "Sheet2"
            Exit Sub
        End If
        With Sheets("List")
            Sheet2.UsedRange.Clear
            .AutoFilterMode = False
            .Range("A1").AutoFilter field:=1, Criteria1:=ManufacturerNum
            .AutoFilter.Range.Copy Sheet2.Range("A1")
            .AutoFilterMode = False
        End With
        Sheet2.Name = ManufacturerNum
        
    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