ComboBox and Showing Data

mharper90

Board Regular
Joined
May 28, 2013
Messages
117
Office Version
  1. 365
Platform
  1. MacOS
I'm trying to take the data from column "C" (excluding the header) on sheet "Health Form Corrections" and display it into "ComboBox1" on "UserForm1" without any duplicates in the combo box.

From that combo box I want to hit "Submit" and have it display all of the data that matches the combo box selection from sheet "Health Form Corrections" onto "Sheet3" (anywhere is ok for now).

I have never figured out how to display data, period. But now I'm also trying to get a combo box without duplicates. Any help is greatly appreciated! Thanks!
 

Excel Facts

Who is Mr Spreadsheet?
Author John Walkenbach was Mr Spreadsheet until his retirement in June 2019.
Code:
Private Sub UserForm_Initialize()
    
    Dim rngUniques As Range, cell As Range
    
    'Filter column C for unique values
    Application.ScreenUpdating = False
    With Sheets("Health Form Corrections")
        If .FilterMode Then .ShowAllData
        .Range("C1", .Range("C" & Rows.Count).End(xlUp)).AdvancedFilter Action:=xlFilterInPlace, Unique:=True
        Set rngUniques = .Range("C2", .Range("C" & Rows.Count).End(xlUp)).SpecialCells(xlCellTypeVisible)
        If .FilterMode Then .ShowAllData
    End With
    Application.ScreenUpdating = True
    
    'Populate combobox from rngUniques
    For Each cell In rngUniques
        ComboBox1.AddItem cell.Value
    Next cell
End Sub
    
    
Private Sub CommandButton1_Click()
    'Submit button
    'Copy filtered data
    If ComboBox1.ListIndex > -1 Then
        Application.ScreenUpdating = False
        With Sheets("Health Form Corrections")
            With .Range("C1", .Range("C" & Rows.Count).End(xlUp))
                .AutoFilter 1, ComboBox1.Value
                .Offset(1).EntireRow.Copy Destination:=Sheets("Sheet3").Range("A1")
            End With
            .AutoFilterMode = False
        End With
        Application.Goto Sheets("Sheet3").Range("A1")
        Application.ScreenUpdating = True
    Else
        MsgBox "Nothing selected in combobox. ", vbExclamation, "Invalid Entry"
    End If
End Sub
 
Upvote 0

Forum statistics

Threads
1,215,596
Messages
6,125,728
Members
449,255
Latest member
whatdoido

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top