We help IT Professionals succeed at work.

Selecting an option within a Combo Box with VB in Excel

Justincut
Justincut asked
on
Hi, I just recorded a Macro in Excel where one clicks on a certain business called "Mortgage Business" within a Combo box in Excel and then copies and pastes the data to another spreadsheet.however, it does not work. Can anyone help?
Comment
Watch Question

Top Expert 2015

Commented:
Can you post your workbook or the macro that you recorded as it will help to do what you are looking for...

Also here is the sample code for your reference which you can use to copy data...

I have assumed the value which you looking for is in A Column in Worksheet-1 starting from row-2 and you want to copy

Sub copydata()

    Dim rng As Range, cell As Range
    Dim lrow As Long
    Dim ws As Worksheet, ws1 As Worksheet

    Set ws = Sheets("Sheet1")
    Set ws1 = Sheets("Sheet2")

    lrow = ws.Cells(Cells.Rows.Count, "a").End(xlUp).Row

    Set rng = ws.Range("A2:A" & lrow)

    For Each cell In rng

        If UCase(Trim(cell.Value)) = UCase(COMBOBOX1.Value) Then
            ws.Cells.EntireRow.Copy ws1.Range("A" & ws1.Cells(Cells.Rows.Count, "a").End(xlUp).Row + 1)
        End If

    Next cell


End Sub

Open in new window


Saurabh...

Author

Commented:
Ok, here's the file. The combo box is in the top left hand corner. I want to choose "MORTGAGE PRODUCTS -EMEA" in the combo box, this will change the data  and then Copy and Paste Cells (i13:y200).
GM-EMEA-Bal-Sheet-January--15-AVG--2-.xl
"There is still no cure for the common birthday." ~John Glenn
Most Valuable Expert 2017
Distinguished Expert 2018
Commented:
Add a module to your workbook and then add this macro.

Sub SelectMortgageProducts()

Sheets("Balance Sheet").Shapes("List Box 1").OLEFormat.Object.Selected(30) = True

End Sub

Open in new window

Martin Liss"There is still no cure for the common birthday." ~John Glenn
Most Valuable Expert 2017
Distinguished Expert 2018

Commented:
You're welcome and I'm glad I was able to help.

In my profile you'll find links to some articles I've written that may interest you.
Marty - MVP 2009 to 2014