Results 1 to 2 of 2

Filter sheet data with ComboBoxes, then Update UserForm with filtered sheet data

Threaded View

  1. #1
    Forum Contributor onmyway's Avatar
    Join Date
    09-03-2012
    Location
    Johannesburg, South Africa
    MS-Off Ver
    2013
    Posts
    386

    Filter sheet data with ComboBoxes, then Update UserForm with filtered sheet data

    Hi all,

    I hope you can help me. This is a 2 part issue.

    I have a dropdown ComboBox filter method i would like to use on a UserForm for filtering my data.

    But the code does not always work properly
    1. i get a lot of Run-time errors (1004) "No cells were found" - especially now that I am using it to filter and select dates or times. I don't know if has to do with the format?
    2. Also, how can the code be modified that the row that is filtered can be used to update my UserForm fields with the filtered data?


    Below is my PREVIOUS search function code used for updating my userform - I would like to accomplish the same effect using the ComboBoxes (drop-downs):

    UserForm Code:

    'SEARCH FUNCTION
    Private Sub TextBox1_Change()
        Dim rng As Range, e
        Dim Ans As Long
        With Me
            .ListBox3.Clear
            If Len(.TextBox1.Value) Then
                For Each e In Sheets("DataBase").Cells(1).CurrentRegion.Columns(1).Offset(1).Value
                    If (e <> "") * (e Like "*" & .TextBox1.Value & "*") Then
                        .ListBox3.AddItem e
                    End If
                Next
                With .ListBox3
                    If .ListCount > 0 Then .ListIndex = 0
                    If .ListCount = 0 Then Ans = MsgBox("No Search reults found, continue?", vbYesNo)
                    If Ans = vbYes Then
                    
                    If MsgBox("Would you like to create a new record?", vbYesNo) = vbYes Then
                    
                    Call ActiveControls
                    
                    End If
                    
                    'Call btnNew_Click
                    Me.cbxEquipmentCommon.SetFocus
                    
             End If
             
        End With
        
        End If
        
        End With
        
    End Sub
    
    'SEARCH FUNCTION
    Private Sub ListBox3_DblClick(ByVal Cancel As MSForms.ReturnBoolean)
    
        Dim ctl As Control
        
        For Each ctl In Me.Controls
            If TypeName(ctl) = "TextBox" Or TypeName(ctl) = "ComboBox" Or TypeName(ctl) = "Checkbox" Then
                ctl.Enabled = True
            End If
        Next ctl
        
        Me.btnSave.Enabled = True
        Me.GUID.Enabled = False
        
    Dim Crit1 As String, FirstRowAdd As String
    Dim LastRow As Long, FirstRow As Long
    
    Crit1 = ListBox3.Value
    LastRow = Sheets("Database").Range("A" & Rows.Count).End(xlUp).Row
    Sheets("DataBase").Range("A4:AQ" & LastRow).AutoFilter Field:=1, Criteria1:=Crit1
    
    FirstRowAdd = FirstVisibleValue(ActiveSheet, 1)
    FirstRow = Range(FirstRowAdd).Row
    
    'Populate Userfrom with values from First Filtered Row
    With UserForm1
    
    .GUID.Value = Sheets("DataBase").Cells(FirstRow, 1).Value
    
    End With
    
    End Sub
    Module Code:

    Function FirstVisibleValue(ByRef Sht As Worksheet, ByVal FilterCol As Long)
        Dim R As Range
        If Sheets("DataBase").AutoFilterMode Then
            Set R = Sheets("DataBase").AutoFilter.Range
            FirstVisibleValue = R.Offset(1, FilterCol - 1).Resize(R.Rows.Count, 1).SpecialCells(12).Cells(1).Address
        End If
    End Function
    Thank you!
    Attached Files Attached Files
    Last edited by onmyway; 01-22-2015 at 07:33 AM.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] Filter worksheet data using 4 dependant comboboxes and populate in 'ListBox' on a userform
    By p_nayak268 in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 09-27-2014, 12:41 PM
  2. [SOLVED] Retrieving data from sheet into userform and being able to update(replace) that data
    By crobando in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 10-25-2012, 09:23 AM
  3. Filter, copy filtered data into another sheet, create a file of that sheet..
    By titushanke in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 06-17-2012, 02:26 PM
  4. Replies: 5
    Last Post: 12-13-2011, 12:40 AM
  5. Update corresponding cells on master sheet when data entered to filtered sheet
    By Sumatied in forum Excel Programming / VBA / Macros
    Replies: 11
    Last Post: 05-18-2011, 09:50 PM

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