+ Reply to Thread
Results 1 to 6 of 6

How do you write a macro that adds ALL worksheets in a combobox?

  1. #1
    Forum Contributor
    Join Date
    12-03-2012
    Location
    London, England
    MS-Off Ver
    Excel 2010
    Posts
    107

    How do you write a macro that adds ALL worksheets in a combobox?

    Hi All,

    I have a combobox in a userform, when I load the userform I want the combobox to show ALL the sheets in the workbook. something like:

    Please Login or Register  to view this content.
    Then after that, all the sheets will be in combobox_allsheet

    how do i do this?

  2. #2
    Forum Guru HaHoBe's Avatar
    Join Date
    02-19-2005
    Location
    Hamburg, Germany
    MS-Off Ver
    work: 2016 on Win10 (notebook), private: 2019 on Win10 (desktop), 2019 on Win11 (notebook)
    Posts
    8,197

    Re: How do you write a macro that adds ALL worksheets in a combobox?

    Hi, kjy1989,

    maybe like this:
    Please Login or Register  to view this content.
    I would recommend to use another name for your variable as Worksheet is a VBA keyword.

    Ciao,
    Holger
    Use Code-Tags for showing your code: [code] Your Code here [/code]
    Please mark your question Solved if there has been offered a solution that works fine for you

  3. #3
    Forum Contributor
    Join Date
    12-03-2012
    Location
    London, England
    MS-Off Ver
    Excel 2010
    Posts
    107

    Re: How do you write a macro that adds ALL worksheets in a combobox?

    Quote Originally Posted by HaHoBe View Post
    Hi, kjy1989,

    maybe like this:
    Please Login or Register  to view this content.
    I would recommend to use another name for your variable as Worksheet is a VBA keyword.

    Ciao,
    Holger
    Thanks Holger,

    I'm new with dealing with Worksheets so even the simplest commands im having trouble with.

    I have another question though

    How do you add a new worksheet that will be named after a value in the textbox.

    something like:

    Please Login or Register  to view this content.

  4. #4
    Forum Contributor
    Join Date
    12-03-2012
    Location
    London, England
    MS-Off Ver
    Excel 2010
    Posts
    107

    Re: How do you write a macro that adds ALL worksheets in a combobox?

    Quote Originally Posted by HaHoBe View Post
    Hi, kjy1989,

    maybe like this:
    Please Login or Register  to view this content.
    I would recommend to use another name for your variable as Worksheet is a VBA keyword.

    Ciao,
    Holger
    Thanks Holger,

    I'm new with dealing with Worksheets so even the simplest commands im having trouble with.

    I have another question though

    How do you add a new worksheet that will be named after a value in the textbox.

    something like:

    Please Login or Register  to view this content.
    how do i do that?



    *Edit: Sorry double post
    Last edited by kjy1989; 01-31-2015 at 05:02 AM.

  5. #5
    Forum Guru HaHoBe's Avatar
    Join Date
    02-19-2005
    Location
    Hamburg, Germany
    MS-Off Ver
    work: 2016 on Win10 (notebook), private: 2019 on Win10 (desktop), 2019 on Win11 (notebook)
    Posts
    8,197

    Re: How do you write a macro that adds ALL worksheets in a combobox?

    Hi, kjy1989,

    a different question but I would check the contents of the textbox to be longer than zero (as well as not being longer than 31 and holding no special characters and name not being present in workbook) and use something like
    Please Login or Register  to view this content.
    Ciao,
    Holger
    Last edited by HaHoBe; 01-31-2015 at 05:22 AM. Reason: corrected code-tag, typos

  6. #6
    Forum Contributor
    Join Date
    12-03-2012
    Location
    London, England
    MS-Off Ver
    Excel 2010
    Posts
    107

    Re: How do you write a macro that adds ALL worksheets in a combobox?

    Hi HaHoBe

    I apologize if it's in the forum rules that one thread would require one question (I read the rules i guess i missed/forgotten that one)
    Thanks the code works. The reason why I posted another question in this thread rather than starting a new one is that my question was so simple and stupid(?) that I wouldnt want to flood the threads with very simple questions. If that is the correct way then so be it.

    And yes i do a google search before i ask these questions in case you might say that i should do a search on simple commands before i post something here.

    Anyway, apologies and if that's the proper way of posting then i'll just start a new thread for every questions. Again, thanks Hahobe!

+ 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. Replies: 1
    Last Post: 09-18-2013, 10:01 AM
  2. Replies: 2
    Last Post: 07-02-2013, 07:03 AM
  3. Macro to write to different worksheets
    By mal.b.graham in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 08-21-2012, 11:41 AM
  4. Replies: 0
    Last Post: 12-22-2011, 03:42 PM
  5. How do you write a macro to link data between 2 worksheets?
    By liur3n in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 10-15-2010, 02:33 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