breynolds0431
Active Member
- Joined
- Feb 15, 2013
- Messages
- 303
- Office Version
- 365
- 2016
- Platform
- Windows
Hi. I have a userform with a combobox that populates worksheet names from the workbook. There are three conditions I want met before adding the worksheet name to the combobox. They are (1) the worksheet must be visible, (2) the worksheet cannot be included in an array of restricted workbook names, which is the
I have the below, but it's ignoring the arr list and adding them all multiple times to the combobox. I've tried a couple variations, but can't seem to wrap my head around why this isn't working...
Attempt 1
Attempt 2
arr
variable, and (3) the workbook name cannot include a hyphen.I have the below, but it's ignoring the arr list and adding them all multiple times to the combobox. I've tried a couple variations, but can't seem to wrap my head around why this isn't working...
Attempt 1
VBA Code:
Dim arr As Variant: arr = Array("START", "INFO", "CY", "CY_orig", "PY", "DATA VERIFY", "FLAGGED DUPLICATES")
Dim a As Variant, ws As Worksheet
For Each ws In ActiveWorkbook.Sheets
If ws.Visible = True And InStr(ws.Name, "-") = 0 Then
For Each a In arr
If Not UCase(ws.Name) = a Then cboSheets.AddItem ws.Name
Next a
End If
Next ws
Attempt 2
VBA Code:
Dim arr As Variant: arr = Array("START", "INFO", "CY", "CY_orig", "PY", "DATA VERIFY", "FLAGGED DUPLICATES")
Dim a As Variant, ws As Worksheet
For Each ws In ActiveWorkbook.Sheets
For Each a In arr
If ws.Visible = True And Not UCase(ws.Name) = a And InStr(ws.Name, "-") = 0 Then cboSheets.AddItem ws.Name
Next a
Next ws