+ Reply to Thread
Results 1 to 13 of 13

Thread: populate combo box from range in different workbook

  1. #1
    Registered User
    Join Date
    11-24-2011
    Location
    Wollongong
    MS-Off Ver
    Excel 2010
    Posts
    9

    populate combo box from range in different workbook

    Hi Everyone

    VBA novice but learning. I have 2 workbooks one called stations and the other services. I would like to use a combo box in services showing the values from column G in stations. Depending on the selection made would then update the values from stations A1 to services C7, stations A3 to services C8 and stations A6 to services C9. There are a few more but Im hoping with a push in the right direction I can manage the rest.

    Having problems, can only get values into combo box with both books open.

    Any help appreciated.

    Regards
    brendonh
    Last edited by brendonh; 02-11-2012 at 06:22 PM.

  2. #2
    Forum Guru, retired Admin royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    25,640

    Re: populate combo box from range in different workbook

    You need to open the other workbook, load the combobox then close the other workbook. Hise this by switching off screen updating

    
    Option Explicit
    
    Private Sub UserForm_Initialize()
        Dim oWbk   As Workbook
        Dim rdata  As Range
    
        Application.ScreenUpdating = False
        'check if workbook containing source is open if not open it.
        If Not WorkbookOpen("P:\Accounts\Billing Schedule.xls") Then
            Set oWkbk = Workbooks.Open("P:\Accounts\Billing Schedule.xls")
        Else: Set oWkbk = Workbooks("P:\Accounts\Billing Schedule.xls")
        End If
        'this is the data to load to combobox
        Set rdata = oWkbk.Worksheets("MASTER SCHEDULE").Range("A5:A103")
    
        With Me.ComboBox1
            .Clear    'clear any previous data
            .Style = fmStyleDropDownList
            .BoundColumn = 0
            'set RowSource
            .RowSource = rdata.Address(external:=True)
            '0 = no selection
            .ListIndex = 0
        End With
    
    
        Set oWbk = Nothing
        Set rdata = Nothing
        Application.ScreenUpdating = True
    End Sub
    Hope that helps.

    RoyUK
    --------
    If you are pleased with a member's answer then use the Star icon to rate it, if you are pleased enough to part with cash consider a donation to Children in Need

    For Excel Tips & Solutions, free examples and tutorials why not check out my downloads

    New members please read & follow the Forum Rules

    Remember to mark your questions Solved and rate the answer(s)

  3. #3
    Registered User
    Join Date
    11-24-2011
    Location
    Wollongong
    MS-Off Ver
    Excel 2010
    Posts
    9

    Re: populate combo box from range in different workbook

    Thanks RoyUK

    I have been trying to get this code to work with my workbooks but getting errors. Should this be in a macro module or should the code be in the sheet or workbook?

    Regards
    brendonh

  4. #4
    Forum Guru, retired Admin royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    25,640

    Re: populate combo box from range in different workbook

    It's for a combobox on a userform. What kind of combobox are you using & where is it?
    Hope that helps.

    RoyUK
    --------
    If you are pleased with a member's answer then use the Star icon to rate it, if you are pleased enough to part with cash consider a donation to Children in Need

    For Excel Tips & Solutions, free examples and tutorials why not check out my downloads

    New members please read & follow the Forum Rules

    Remember to mark your questions Solved and rate the answer(s)

  5. #5
    Registered User
    Join Date
    11-24-2011
    Location
    Wollongong
    MS-Off Ver
    Excel 2010
    Posts
    9

    Re: populate combo box from range in different workbook

    Hi RoyUK

    I have a Combo Box from Form Control (now DropDown15) in my services workbook (Sheet1). I can get it to show column G from from the stations workbook (sheet1) by referencing it from the properties Input Range. This is where I start to struggle, once a selection is made eg: Sutherland (from stations workbook, column G row 17). I would like to have this happening in the background but also need to get other values from stations A1 value to services C7, stations A3 value to services C8. As mentioned I'm hoping for a push in the right direction to learn I don't want someone to do it for me.

    Regards
    brendonh

  6. #6
    Forum Guru snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,151

    Re: populate combo box from range in different workbook

    If you use an ActiveX combobox you can load the whole sheet in workbook 'stations' into that combobox.
    Dependent of what you want you can show all data or only some columns. You can make changes in the combobox's values. and when done write those result directly into the workbook 'stations'.



  7. #7
    Forum Guru, retired Admin royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    25,640

    Re: populate combo box from range in different workbook

    My code will not work with forms comboboxes. You really need to make sure that you give us as much information as possible.
    Hope that helps.

    RoyUK
    --------
    If you are pleased with a member's answer then use the Star icon to rate it, if you are pleased enough to part with cash consider a donation to Children in Need

    For Excel Tips & Solutions, free examples and tutorials why not check out my downloads

    New members please read & follow the Forum Rules

    Remember to mark your questions Solved and rate the answer(s)

  8. #8
    Registered User
    Join Date
    11-24-2011
    Location
    Wollongong
    MS-Off Ver
    Excel 2010
    Posts
    9

    Re: populate combo box from range in different workbook

    Thanks RoyUK

    I will have another go at it today, fresh start. If I can't get it working I will upload the workbooks.

    Regards
    Brendon

  9. #9
    Registered User
    Join Date
    11-24-2011
    Location
    Wollongong
    MS-Off Ver
    Excel 2010
    Posts
    9

    Re: populate combo box from range in different workbook

    Hi RoyUK

    I have uploaded the workbooks to see if I can get help. Getting the combo box populated is working. From here I want to select a Fire Station in the combo box and populate the text boxes from the row matching the selected depot. The last step would be to transpose the data from the form to the services workbook.

    Regards
    brendonh
    Attached Files Attached Files

  10. #10
    Forum Guru snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,151

    Re: populate combo box from range in different workbook

    To read more about how to use a userform as a database entryform look here.



  11. #11
    Forum Guru, retired Admin royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    25,640

    Re: populate combo box from range in different workbook

    See the DatabaseForm
    Hope that helps.

    RoyUK
    --------
    If you are pleased with a member's answer then use the Star icon to rate it, if you are pleased enough to part with cash consider a donation to Children in Need

    For Excel Tips & Solutions, free examples and tutorials why not check out my downloads

    New members please read & follow the Forum Rules

    Remember to mark your questions Solved and rate the answer(s)

  12. #12
    Registered User
    Join Date
    11-24-2011
    Location
    Wollongong
    MS-Off Ver
    Excel 2010
    Posts
    9

    Re: populate combo box from range in different workbook

    Thanks RoyUK and snb

    Regards
    brendonh

  13. #13
    Registered User
    Join Date
    11-24-2011
    Location
    Wollongong
    MS-Off Ver
    Excel 2010
    Posts
    9

    Re: populate combo box from range in different workbook

    Once again thanks to ROYUK and snb for a push in the right direction. The code is now working as I want it to, RoyUK's link was especially helpful.

    Regards
    brendonh

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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.2.0