+ Reply to Thread
Results 1 to 6 of 6

List Results in Userform

  1. #1
    Registered User
    Join Date
    09-27-2010
    Location
    Christchurch, NZ
    MS-Off Ver
    Excel 2003
    Posts
    23

    List Results in Userform

    Hi all,

    I have done my best to create the worksheet attached making some sacrifices at the same time, for example on UserForm1 I was unable to get this to create a sequential reference number using "SBCRXXXX" so have gone for a random, which is ok as long as it doesn't repeat.

    My biggest problem at present is USERFORM3, that the search option whilst it works by giving a row number doesn't display all the information I want from the row. I have so far spent a number of days using different tips and tricks I could find to get this working in its current state, is anyone able to please have a look at the coding and see why this might be?

    Private Sub CommandButton1_Click()
    'SEARCH

    Dim Cnt As Long
    Dim Col As Variant
    Dim FirstAddx As String
    Dim FoundMatch As Range
    Dim LastRow As Long
    Dim R As Long
    Dim StartRow As Long
    Dim Wks As Worksheet

    StartRow = 2
    Set Wks = Sheets(1)

    Col = ComboBox1.ListIndex + 1
    If Col = 0 Then
    MsgBox "Please choose a category to search."
    Exit Sub
    End If

    If TextBox1.Text = "" Then
    MsgBox "Please enter a search term."
    TextBox1.SetFocus
    Exit Sub
    End If

    LastRow = Wks.Cells(Rows.Count, Col).End(xlUp).Row
    LastRow = IIf(LastRow < StartRow, StartRow, LastRow)

    Set rng = Wks.Range(Wks.Cells(2, Col), Wks.Cells(LastRow, Col))

    Set FoundMatch = rng.Find(What:=TextBox1.Text, _
    After:=rng.Cells(1, 1), _
    LookAt:=xlWhole, _
    LookIn:=xlValues, _
    SearchOrder:=xlByRows, _
    SearchDirection:=xlNext, _
    MatchCase:=False)

    If Not FoundMatch Is Nothing Then
    FirstAddx = FoundMatch.Address
    ListView1.ListItems.Clear

    Do
    Cnt = Cnt + 1
    R = FoundMatch.Row
    ListView1.ListItems.Add Index:=Cnt, Text:=R
    For Col = 1 To 26
    Set C = Wks.Cells(R, Col)
    ListView1.ListItems(Cnt).ListSubItems.Add Index:=Col, Text:=C.Text
    Next Col
    Set FoundMatch = rng.FindNext(FoundMatch)
    Loop While FoundMatch.Address <> FirstAddx And Not FoundMatch Is Nothing
    SearchRecords = Cnt
    Else
    ListView1.ListItems.Clear
    SearchRecords = 0
    MsgBox "No match found for " & TextBox1.Text
    End If

    End Sub

    Private Sub ListView1_BeforeLabelEdit(Cancel As Integer)

    End Sub

    Private Sub UserForm_Activate()

    Dim C As Long
    Dim I As Long
    Dim R As Long
    Dim Wks As Worksheet

    With ListView1
    .Gridlines = True
    .View = lvwReport
    .HideSelection = False
    .FullRowSelect = True
    .HotTracking = True
    .HoverSelection = False
    .ColumnHeaders.Add Text:="Job Sheet", Width:=64
    End With

    Set Wks = Sheets(1)

    For C = 1 To 13
    ListView1.ColumnHeaders.Add Text:=Wks.Cells(1, C).Text
    ComboBox1.AddItem Wks.Cells(8, C).Text
    Next C

    End Sub

    Thank you very much in advance,

    Daniel
    Attached Files Attached Files

  2. #2
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,643

    Re: List Results in Userform

    Quote Originally Posted by danweeks20 View Post
    My biggest problem at present is USERFORM3, that the search option whilst it works by giving a row number doesn't display all the information I want from the row.
    What info is missing? You don't give any specifics.

    It seems to work for me once I changed the number of columns in the code below. I then had 22 columns of info for each matched row if that's what you mean by; "doesn't display all the information".



    Please Login or Register  to view this content.
    Surround your VBA code with CODE tags e.g.;
    [CODE]your VBA code here[/CODE]
    The # button in the forum editor will apply CODE tags around your selected text.

  3. #3
    Registered User
    Join Date
    09-27-2010
    Location
    Christchurch, NZ
    MS-Off Ver
    Excel 2003
    Posts
    23

    Re: List Results in Userform

    Hi,

    When I say no information, all I get is the row number even with the change of columns in the code. They sit side by side and do not show the row of information in full as a result.

    I have attached a screenshot of the result I receive.

    results.jpg

    There are no lines or anything that appear and the full row of information is what I am trying to get this to display, including multiple results.

    Hope that makes sense?

    Thanks
    Daniel

  4. #4
    Forum Expert mike7952's Avatar
    Join Date
    12-17-2011
    Location
    Florida
    MS-Off Ver
    Excel 2007, Excel 2016
    Posts
    3,520

    Re: List Results in Userform

    Try out the attached file, Uses adodb to query your Job Sheet. Loads combobox2 with values from sheet from what is selected combox1. Click search.
    Thanks,
    Mike

    If you are satisfied with the solution(s) provided, please mark your thread as Solved.
    Select Thread Tools-> Mark thread as Solved.

  5. #5
    Registered User
    Join Date
    09-27-2010
    Location
    Christchurch, NZ
    MS-Off Ver
    Excel 2003
    Posts
    23

    Re: List Results in Userform

    Quote Originally Posted by mike7952 View Post
    Try out the attached file, Uses adodb to query your Job Sheet. Loads combobox2 with values from sheet from what is selected combox1. Click search.
    Hi Mike,
    This works great! Only problem I have is when this is uploaded to One Drive as it is shared between the two of us the search key cannot find the file.
    Is there any fix around this?
    Thanks
    Dan

  6. #6
    Forum Expert mike7952's Avatar
    Join Date
    12-17-2011
    Location
    Florida
    MS-Off Ver
    Excel 2007, Excel 2016
    Posts
    3,520

    Re: List Results in Userform

    what path are you using?

+ 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. Userform Combobox - select from list, store this as default each time userform loads
    By thecdnmole in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 10-19-2014, 07:48 AM
  2. Userform Results
    By MKnuep in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 08-26-2014, 01:12 PM
  3. UserForm help - display list of open workbooks except workbook userform code is in
    By kensweep in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 01-09-2014, 12:26 PM
  4. Replies: 3
    Last Post: 10-30-2013, 09:18 AM
  5. Userform Search Function Autofilter Results and Repopulate Userform
    By cindy71 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 08-16-2012, 03:46 PM
  6. UserForm to search sheet, show results on separate userform?
    By egemenkepekci in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 05-25-2010, 01:06 PM
  7. Replies: 2
    Last Post: 08-18-2006, 05:28 AM

Tags for this Thread

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