Excel VBAListbox

GRCArizona

Board Regular
Joined
Apr 24, 2010
Messages
95
Hi - I'm populating a ListBox with the names of all Visible Sheets. I've got everything working fine except for 1 thing. I'd like to EXCLUDE the Activesheet from the list that populates the ListBox.

Any suggestions?

thx,

GRC
 

Excel Facts

Create a chart in one keystroke
Select the data and press Alt+F1 to insert a default chart. You can change the default chart to any chart type
What's the code you have so far?
 
Upvote 0
Private Sub PlanType_Change()

Dim AllTabs As Worksheet, firsttab As Worksheet

AvailableList.Clear '''''AvailableList is the 1st ListBox

Set firsttab = ActiveSheet

For Each AllTabs In ThisWorkbook.Sheets

If AllTabs.Visible = xlSheetVisible Then

AllTabs.Activate
If ActiveSheet.Range("A2").Value = PlanType.Value Then
AvailableList.AddItem AllTabs.Name
End If
End If
Next
firsttab.Activate
 
Upvote 0
Maybe ...

Code:
Private Sub PlanType_Change()
    Dim wks         As Worksheet
 
    AvailableList.Clear
 
    For Each wks In ThisWorkbook.Worksheets
        If Not wks Is Me Then
            If wks.Visible = xlSheetVisible Then
                If wks.Range("A2").Value = PlanType.Value Then
                    AvailableList.AddItem wks.Name
                End If
            End If
        End If
    Next
End Sub
 
Upvote 0
Thx for the code. It errored out and I saw that it needed an extra "End If" before the "Next", but it is still populating with the Active Sheet.

I was thinking about trying to use sth like:

If(And....xlSheetVisible AND Not Activesheet Then.... AddItem.

Not sure how this code would look though.
 
Upvote 0
I just created the sheet (again) and ran the code exactly as written, and it worked fine. I assumed that PlanType and AvailableList are ActiveX controls on the same sheet and that the code in in the worksheet module.
 
Upvote 0
I'm using a Command Button on a worksheet that opens up a UserForm. The 'Plan Type:' is a Combobox that sends the available worksheets over to the ListBox I'm trying to populate.

sorry for the confusion.
 
Upvote 0

Forum statistics

Threads
1,224,505
Messages
6,179,152
Members
452,891
Latest member
JUSTOUTOFMYREACH

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top