+ Reply to Thread
Results 1 to 4 of 4

Set active Worksheet from a ComboBox value.

  1. #1
    Registered User
    Join Date
    01-18-2016
    Location
    Manchester, England
    MS-Off Ver
    Office 10
    Posts
    2

    Set active Worksheet from a ComboBox value.

    Hi this is my first post, I've not coded for some time until recently so my vba Knowledge may be a little rusty and not upto date with the newest versions of Excel.

    I have a userform with dependant comboboxes, textbox, date etc that works great, but the sheet names are hardcoded. (see below code)

    Please Login or Register  to view this content.

    I wish to change the hard coding ("Fruit Exp") that sets the active sheet to the same name as selected in the cmbType .

    Should I try case function?


    I hope I've explained the problem clearly enough.

    Thank you in advance for any help you can offer.

    Cheers

    MaxSheets

    Update.

    I've Changed this code line and similar, {ThisWorkbook.Worksheets("Data").Range("A1")}
    this eliminates one of the hard coded name values.

    Please Login or Register  to view this content.
    Last edited by MaxSheets; 01-18-2016 at 06:18 AM.

  2. #2
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,659

    Re: Set active Worksheet from a ComboBox value.

    Try something like this...

    Please Login or Register  to view this content.
    Surround your VBA code with CODE tags e.g.;
    [CODE]your VBA code here[/CODE]
    The # button in the forum editor will apply CODE tags around your selected text.

  3. #3
    Registered User
    Join Date
    01-18-2016
    Location
    Manchester, England
    MS-Off Ver
    Office 10
    Posts
    2

    Re: Set active Worksheet from a ComboBox value.

    Thank You AlphaFrog.

    It was my assumption you needed a string for a sheet name.
    your answer has allowed me to point the cmbType value to the sheet name.

    See Below

    Please Login or Register  to view this content.
    Many thanks

    Ps Im not sure how to label this thread solved?

  4. #4
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,659

    Re: Set active Worksheet from a ComboBox value.

    You're welcome.

    cmbType.Value is a string when an item is selected.

    This tests if any item from the combobox's list is selected.
    If cmbType.ListIndex > -1 Then

    I don't follow the need for your If-ElseIf statements, but if it works for you then go for it.

+ 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: 4
    Last Post: 07-03-2015, 04:27 AM
  2. On ActiveX ComboBox Change, switch focus to the active worksheet
    By ericbartha in forum Excel Programming / VBA / Macros
    Replies: 11
    Last Post: 06-29-2015, 10:54 AM
  3. ComboBox Selection Caused Cells to be copied to active worksheet
    By octalman in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 04-07-2015, 02:12 PM
  4. Replies: 1
    Last Post: 07-07-2014, 09:19 AM
  5. Selecting an active worksheet AND an active table that keep changing names!
    By brucemc777 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 01-12-2014, 10:22 PM
  6. combobox cannot read active worksheet
    By craig2793 in forum Excel Programming / VBA / Macros
    Replies: 12
    Last Post: 07-11-2013, 02:59 AM
  7. Macro to edit active chart on active worksheet
    By shlurpee in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 05-07-2011, 04:58 AM

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