Consulting

Results 1 to 8 of 8

Thread: Sheets Selection Through Combobox

  1. #1

    Question Sheets Selection Through Combobox

    Sir

    I have got 10 sheets in a workbook having different names. I want a ComboBox in every sheet displaying names of all sheets in combobox and when i select a name of sheet from combobox it goes to that sheet after hidding sheet where selection was made and running macro codes which i have developed for sheet. I want only one sheet display on the screen when one selection is made other one is invisible.

    Ayazgreat

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    [vba]

    Private Sub Workbook_BeforeClose(Cancel As Boolean)
    On Error Resume Next
    Application.CommandBars("SheetList").Delete
    On Error GoTo 0
    End Sub

    Private Sub Workbook_Open()
    Dim sh As Worksheet


    On Error Resume Next
    Application.CommandBars("SheetList").Delete
    On Error GoTo 0

    With Application.CommandBars.Add(Name:="SheetList", temporary:=True)

    With .Controls.Add(Type:=msoControlComboBox)

    For Each sh In ThisWorkbook.Worksheets

    .AddItem sh.Name
    Next sh
    .OnAction = "SelectSheet"
    End With
    .Visible = True
    End With

    End Sub
    [/vba]

    This is workbook event code.
    To input this code, right click on the Excel icon on the worksheet
    (or next to the File menu if you maximise your workbooks),
    select View Code from the menu, and paste the code

    And then in a standard code module, add

    [vba]

    Public Sub SelectSheet()
    Dim sh As Worksheet

    With Application.CommandBars.ActionControl

    ThisWorkbook.Worksheets(.Text).Visible = xlSheetVisible
    For Each sh In ThisWorkbook.Worksheets

    If sh.Name <> .Text Then

    sh.Visible = xlSheetHidden
    End If
    Next sh
    End With
    End Sub
    [/vba]
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  3. #3
    Thanks Sir for your reply but i am sorry to say that I have inserted combobox in sheet from form in sheet so in this case i need a macro for inserted combobox from selection sheets there as mentioned below.



    [IMG]file:///C:/DOCUME~1/AYAZAK~1/LOCALS~1/Temp/msohtml1/01/clip_image001.gif[/IMG]

  4. #4
    Kindly see attached file for example.

  5. #5
    Tow more problems iare that if new sheets are inserted then

    1- More sheets are visible then one
    2- Sheets box is not updated when new sheets are inserted.

  6. #6
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    I am not going to give you a solution along your suggestion, that is just a dumb way of doing it.

    Here is how you should do it. If you like it, use it, if not, throw it away.
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  7. #7
    Thanks i will try to use it

  8. #8

    thanx

    Thanx dude...will try that.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •