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?
 

Some videos you may like

Excel Facts

Copy PDF to Excel
Select data in PDF. Paste to Microsoft Word. Copy from Word and paste to Excel.

My Aswer Is This

Well-known Member
Joined
Jul 5, 2014
Messages
17,402
Office Version
  1. 2013
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?
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.
 

TRY369

New Member
Joined
Dec 16, 2020
Messages
12
Office Version
  1. 365
Platform
  1. Windows
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..
 

My Aswer Is This

Well-known Member
Joined
Jul 5, 2014
Messages
17,402
Office Version
  1. 2013
Platform
  1. Windows
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.
 

TRY369

New Member
Joined
Dec 16, 2020
Messages
12
Office Version
  1. 365
Platform
  1. Windows

ADVERTISEMENT

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
 

My Aswer Is This

Well-known Member
Joined
Jul 5, 2014
Messages
17,402
Office Version
  1. 2013
Platform
  1. Windows
You could add a line like this to your script:
ComboBox1.AddItem StrName
 
Solution

Watch MrExcel Video

Forum statistics

Threads
1,126,972
Messages
5,621,892
Members
415,864
Latest member
cybid

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
Top