Link to home
Start Free TrialLog in
Avatar of Justincut
Justincut

asked on

Selecting an option within a Combo Box with VB in Excel

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?
Avatar of Saurabh Singh Teotia
Saurabh Singh Teotia
Flag of India image

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...
Avatar of Justincut
Justincut

ASKER

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
ASKER CERTIFIED SOLUTION
Avatar of Martin Liss
Martin Liss
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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