How to add new sheet name onto userform combobox?

TRY369

New Member
Joined
Dec 16, 2020
Messages
12
Office Version
  1. 365
Platform
  1. Windows
Hi all,
So i have this userform which can creates new sheet upon clicking a button. But at the same time i have a combobox which also shows the name of the sheet list.
However, I was not able to display the newly created sheets name onto the userform combobox.

This is my current code
VBA Code:
Private Sub UserForm_Initialize()

    For Each ws In Worksheets
        If ws.Name <> "LogBook" Then
            Me.ComboBox1.AddItem ws.Name
        End If
    Next ws
  
End Sub

Anyone has any idea?
 

Excel Facts

Copy a format multiple times
Select a formatted range. Double-click the Format Painter (left side of Home tab). You can paste formatting multiple times. Esc to stop
Hi all,
So i have this userform which can creates new sheet upon clicking a button. But at the same time i have a combobox which also shows the name of the sheet list.
However, I was not able to display the newly created sheets name onto the userform combobox.

This is my current code
VBA Code:
Private Sub UserForm_Initialize()

    For Each ws In Worksheets
        If ws.Name <> "LogBook" Then
            Me.ComboBox1.AddItem ws.Name
        End If
    Next ws
 
End Sub

Anyone has any idea?
The code you showed only runs when you open the Userform.
So if you have a script on the Userform that creates new sheets you will have to close the userform and next time you open Userform you should get all your sheet names loaded into the combobox. It works for me.
 
Upvote 0
I do have a script for creating sheets, but after i created a sheet on userform, I want the new sheet name to appear onto the combobox without having to close the application/userform..
 
Upvote 0
I do have a script for creating sheets, but after i created a sheet on userform, I want the new sheet name to appear onto the combobox without having to close the application/userform..
Show me the script that creates new sheets.
 
Upvote 0
VBA Code:
Dim ws As Worksheet
Dim wsM As Worksheet
Dim strName As String
Dim bCheck As Boolean

On Error Resume Next
Set wsM = Sheets("MasterList")
        strName = Format(Date, "yyyy")
        bCheck = Len(Sheets(strName).Name) > 0

    If bCheck = False Then

        wsM.COpy After:=Sheets(Sheets.Count)
        ActiveSheet.Name = strName
    End If

So basically this script is duplicating the masterlist and naming into a new year
 
Upvote 0
You could add a line like this to your script:
ComboBox1.AddItem StrName
 
Upvote 0
Solution

Forum statistics

Threads
1,214,614
Messages
6,120,520
Members
448,968
Latest member
Ajax40

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