+ Reply to Thread
Results 1 to 11 of 11

Combobox not loading the items if the source sheet is not activated

  1. #1
    Valued Forum Contributor ImranBhatti's Avatar
    Join Date
    03-27-2014
    Location
    Rawalpindi,Pakistan
    MS-Off Ver
    Office 365
    Posts
    1,784

    Combobox not loading the items if the source sheet is not activated

    Hi

    In the attached workbook, I have a userform
    the combobox ComboMainHead is being populated from the chart of accounts sheet. the problem is if the said sheet is not activated the combox is not populated.

    What am I am doing wrong

    Here is the code behind the userform
    Please Login or Register  to view this content.
    Attached Files Attached Files
    Last edited by ImranBhatti; 12-25-2017 at 11:24 AM.
    Teach me Excel VBA

  2. #2
    Forum Guru sktneer's Avatar
    Join Date
    04-30-2011
    Location
    Kanpur, India
    MS-Off Ver
    Office 365
    Posts
    9,648

    Re: Combobox not loading the items if the source sheet is not activated

    Replace existing UserForm_Initialize code with the following one...

    Please Login or Register  to view this content.
    Regards
    sktneer


    Treat people the way you want to be treated. Talk to people the way you want to be talked to.
    Respect is earned NOT given.

  3. #3
    Valued Forum Contributor ImranBhatti's Avatar
    Join Date
    03-27-2014
    Location
    Rawalpindi,Pakistan
    MS-Off Ver
    Office 365
    Posts
    1,784

    Re: Combobox not loading the items if the source sheet is not activated

    Guru G

    The problem is if I call the userform from the Database then the said combobox is not getting populated even with the amended code. This is what I just came to know. It should be populated if I call the userform from Database.
    Last edited by ImranBhatti; 12-25-2017 at 11:25 AM.

  4. #4
    Forum Guru sktneer's Avatar
    Join Date
    04-30-2011
    Location
    Kanpur, India
    MS-Off Ver
    Office 365
    Posts
    9,648

    Re: Combobox not loading the items if the source sheet is not activated

    After making the changes, if I click the button called "Show Voucher Entry Form" on DataBase sheet, the ComboBox gets populated as desired.

    Please refer to the demo video.
    Attached Files Attached Files

  5. #5
    Forum Guru
    Join Date
    09-10-2017
    Location
    Chippenham, England
    MS-Off Ver
    365
    Posts
    15,080

    Re: Combobox not loading the items if the source sheet is not activated

    Whilst the code supplied by sktneer worked for me, how about
    Please Login or Register  to view this content.

  6. #6
    Forum Guru bakerman2's Avatar
    Join Date
    10-03-2012
    Location
    Antwerp, Belgium
    MS-Off Ver
    MO Prof Plus 2016
    Posts
    6,908

    Re: Combobox not loading the items if the source sheet is not activated

    Works fine for me.

    Please Login or Register  to view this content.
    Avoid using Select, Selection and Activate in your code. Use With ... End With instead.
    You can show your appreciation for those that have helped you by clicking the * at the bottom left of any of their posts.

  7. #7
    Valued Forum Contributor ImranBhatti's Avatar
    Join Date
    03-27-2014
    Location
    Rawalpindi,Pakistan
    MS-Off Ver
    Office 365
    Posts
    1,784

    Re: Combobox not loading the items if the source sheet is not activated

    All you Gurus are correct at your place. If by means of the amended codes the ComboMainHead is populated then the second depended combobox is not populated.Please select the second item from the Mian Head and then click on sub Head combo.

  8. #8
    Forum Guru sktneer's Avatar
    Join Date
    04-30-2011
    Location
    Kanpur, India
    MS-Off Ver
    Office 365
    Posts
    9,648

    Re: Combobox not loading the items if the source sheet is not activated

    The issue with both of your codes is because of the way you are trying to find the last used row in column A. Look at the bold part in the For Loop...
    For Each cell In Sheet4.Range("A3:A" & Cells(Rows.Count, 1).End(xlUp).Row)
    This part is not qualified with the Sheet reference so it would always find the last row used in column A on the ActiveSheet.
    So all you need is to make the same change in the ComboMainHead_Change code as well.

    Try it like this...

    Please Login or Register  to view this content.

  9. #9
    Forum Guru bakerman2's Avatar
    Join Date
    10-03-2012
    Location
    Antwerp, Belgium
    MS-Off Ver
    MO Prof Plus 2016
    Posts
    6,908

    Re: Combobox not loading the items if the source sheet is not activated

    Is this what you mean ?
    Please Login or Register  to view this content.

  10. #10
    Valued Forum Contributor ImranBhatti's Avatar
    Join Date
    03-27-2014
    Location
    Rawalpindi,Pakistan
    MS-Off Ver
    Office 365
    Posts
    1,784

    Re: Combobox not loading the items if the source sheet is not activated

    Quote Originally Posted by sktneer View Post
    The issue with both of your codes is because of the way you are trying to find the last used row in column A. Look at the bold part in the For Loop...
    For Each cell In Sheet4.Range("A3:A" & Cells(Rows.Count, 1).End(xlUp).Row)
    This part is not qualified with the Sheet reference so it would always find the last row used in column A on the ActiveSheet.
    So all you need is to make the same change in the ComboMainHead_Change code as well.

    Try it like this...

    Please Login or Register  to view this content.
    Dhanayawaad Guru Ji!
    That worked like a charm.much much appreciated.

    Thanks to bakerman and others who tried their best to help out.

  11. #11
    Forum Guru sktneer's Avatar
    Join Date
    04-30-2011
    Location
    Kanpur, India
    MS-Off Ver
    Office 365
    Posts
    9,648

    Re: Combobox not loading the items if the source sheet is not activated

    You're welcome Imran! Glad we could help.
    Thanks for the feedback.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. ComboBox values source being changed based on another combobox selection in a UserForm
    By stephenanderson in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 02-08-2016, 11:12 PM
  2. Add items in combobox in a sheet
    By siobeh in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 12-03-2013, 03:27 AM
  3. Loading from external source and looking cells
    By johnph in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 01-02-2013, 04:23 PM
  4. Loading Images on Sheet Based On ComboBox
    By Muhnamana in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 04-25-2010, 12:25 PM
  5. Combobox not loading
    By sentinela in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 05-14-2009, 06:13 PM
  6. Items From Sheet In Combobox
    By vroemans in forum Excel General
    Replies: 1
    Last Post: 01-12-2007, 03:56 AM
  7. [SOLVED] Loading sheet names in Combobox
    By Sige in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 09-16-2005, 01:05 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