+ Reply to Thread
Results 1 to 2 of 2

How to refer a combobox with a dynamic worksheet.

  1. #1
    Registered User
    Join Date
    06-13-2017
    Location
    Malaysia
    MS-Off Ver
    2010
    Posts
    1

    How to refer a combobox with a dynamic worksheet.

    Hi All,

    I'm new here. I need help on the below

    I have a ComboBox1 defined in sheet (“ABC”). This combo will call a Sub in Module 2 to assign the selection list for the combobox plus other tasks. This is works fine.

    Sheet(“ABC”)
    Option Explicit
    Private Sub ComboBox1_Change()
    Application.EnableEvents = False
    …..
    Application.Run "Module2.AssignSelectionList"
    …..
    End Sub

    Module 2
    Option Explicit

    Sub AssignSelectionList()
    Dim SelectionArray As Variant
    Application.ScreenUpdating = False
    Application.DisplayAlerts = False
    Application.EnableEvents = False

    Worksheets("ABC").ComboBox1.List = SelectionArray

    Application.ScreenUpdating = True
    Application.DisplayAlerts = True
    Application.EnableEvents = True

    End Sub

    But when user try to copy sheet (“ABC”) to multiple sheets, for example Sheet(“ABC (2)”), Sheet(“ABC(3)”) and so on, the above VBA will not work. So I have to define make worksheet name as variable as per below in Module 2. All the sheets will have a combobox named Combobox1.

    Sheet(“ABC”)
    Option Explicit
    Private Sub Worksheet_Activate()
    ActiveWs = ThisWorkbook.ActiveSheet.Name
    End Sub
    Private Sub ComboBox1_Change()
    Application.EnableEvents = False
    …..
    Application.Run "Module2.AssignSelectionList"
    …..
    End Sub

    Module 2
    Option Explicit

    Public ActiveWS as

    Sub AssignSelectionList()
    Dim SelectionArray As Variant
    Dim Ws1 As Worksheet
    Application.ScreenUpdating = False
    Application.DisplayAlerts = False
    Application.EnableEvents = False

    Set Ws1 = Worksheets(ActiveWs)
    Ws1.ComboBox1.List = SelectionArray

    Application.ScreenUpdating = True
    Application.DisplayAlerts = True
    Application.EnableEvents = True

    End Sub

    This is not works! I have a compile error: Method or data member not found.
    Thank you in advance.

  2. #2
    Forum Expert
    Join Date
    12-14-2012
    Location
    London England
    MS-Off Ver
    MS 365 Office Suite.
    Posts
    8,448

    Re: How to refer a combobox with a dynamic worksheet.

    Welcome

    Unfortunately I cannot help you yet as:-


    Your post does not comply with Rule 3 of our Forum RULES. Use code tags around code.

    Posting code between [CODE]Please [url=https://www.excelforum.com/login.php]Login or Register [/url] to view this content.[/CODE] tags makes your code much easier to read and copy for testing, it also maintains VBA formatting.

    Click on Edit to open your thread, then highlight your code and click the # icon at the top of your post window. More information about these and other tags can be found here

    (This thread should receive no further responses until this moderation request is fulfilled, as per Forum Rule 7)
    My General Rules if you want my help. Not aimed at any person in particular:

    1. Please Make Requests not demands, none of us get paid here.

    2. Check back on your post regularly. I will not return to a post after 4 days.
    If it is not important to you then it definitely is not important to me.

+ 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. [SOLVED] Refer to Combobox passed as parameter by string variable name
    By TC1980 in forum Excel Programming / VBA / Macros
    Replies: 14
    Last Post: 12-23-2016, 08:53 AM
  2. VB UserForm ComboBox List Based On Dynamic Named Range in Worksheet
    By huntethic in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 04-14-2015, 02:45 PM
  3. [SOLVED] UserForm , ComboBox 2 , refer to selection in Combo Box 1
    By waihar in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 10-08-2013, 01:40 AM
  4. [SOLVED] Refer to Combobox on another sheet
    By dreddster in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 08-05-2013, 10:48 AM
  5. [SOLVED] Refer to a combobox not created in a userform in VBA
    By Hugo-F in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 04-22-2013, 04:33 AM
  6. Refer to combobox in userform with variable
    By lif in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 06-25-2006, 06:25 AM
  7. using a listbox or combobox to refer to columns or sheets
    By fern in forum Excel Programming / VBA / Macros
    Replies: 36
    Last Post: 04-03-2005, 01:42 AM

Tags for this Thread

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