Vba UserForm combobox items don't apear till i click on the userform

Muhammed Saddam

I have a command button, when i click it, it shows a customized userform which contains a combobox with items taken from a sheet cells. the user is suppose to press the command then the userform appears, he needs to select one item from the list, the item is a sheet name in different workbook, accordingly it will import the data from that sheet. however i am facing a problem: when the userform appears, i click on the combobox it shows no items, then if i click once on the userform then check the combobox again it shows the items correctly, if i click again on the userform, the combobox items will be doulbled! if i selected an item it works perfectly. So what i want to achieve is: i want the combobox to show the items directly without clicking on the userform. the code is this:

In the userform:

Private Sub UserForm_Click()



Dim mlf As Workbook

Dim adad As Long

Dim mada As String

Dim lastRow As Long

Set mlf = ActiveWorkbooklastRow = Sheet3.Cells(Rows.Count, 1).End(xlUp).Row

For adad = 1 To lastRow

mada = Sheet3.Cells(adad, 1)

With ComboBox1

        .AddItem mada

End With

Next

    End Sub


Private Sub cmdOkay_Click()

 'Verify that an item was selected

If Me.ComboBox1.BoundValue = vbNullString Then

    MsgBox "You did not choose an item!", vbOKOnly

    Exit Sub

Else

    MsgBox "You have selected " & Me.ComboBox1.BoundValue, vbOKOnly

    Sheet3.Cells(1, 2) = Me.ComboBox1.BoundValue


End If

   Unload Me 

End Sub

In the CommandButton

Dim testbook As Workbook

Set testbook = ThisWorkbook

Set database = Workbooks.Open(Filename:=myPath & myFile)

testbook.Worksheets("Sheet4").Range("A1:B5").Clear

With UserForm1
.Caption = "Settings of the test"
End With

Dim lo As Integer

For lo = 1 To database.Sheets.Count

     testbook.Sheets("Sheet4").Cells(lo, 1) = database.Worksheets(lo).Name

Next

UserForm1.Show
Siddharth Rout

That is because you are telling it to do that on the click event.

Change

Private Sub UserForm_Click()

to

Private Sub UserForm_Initialize()

Once you change this, the combobox issue will also go away.

この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。

侵害の場合は、連絡してください[email protected]

編集
0

コメントを追加

0

関連記事

分類Dev

UserForm ComboBox

分類Dev

VBA UserForm label in spreadsheet

分類Dev

sql source for a vba userform

分類Dev

How do I call a module from my userform in vba?

分類Dev

Chosen result from Worksheet cell to Userform Combobox

分類Dev

VBA - destroy a modeless UserForm instance properly

分類Dev

Excel VBA UserForm printscreen save as pdf

分類Dev

Double click event in the excel sheet column to fill all textboxes of a Userform

分類Dev

Excel UserForm button click slow response time when clicked fast

分類Dev

VBA Entering userform data at next blank row correctly

分類Dev

Excel VBA Userform Listbox Dynamic Context Menu Using .OnAction Method

分類Dev

VBA USERFORMエラー6の回避策

分類Dev

Update a userform listbox after userform initialization

分類Dev

Auto Size/Adjust Userform

分類Dev

Conflict bewteen OLEObjects and Userform

分類Dev

Put variable in UserForm name

分類Dev

Self Adjusting Userform Size

分類Dev

Userform not copying data to spreadsheet

分類Dev

vba userform , if any of the checkboxes in the frame is true then macro should not be applied on the sheetname mentioned in the checkbox

分類Dev

VBA: How to change default selection on a Userform & restrict user from texting values under a dropdown column

分類Dev

Excel VBA:USerform P&Lが列に入力されました

分類Dev

VBA -How to properly Find, Copy and Paste a Search from a Command Button on a Userform?

分類Dev

VBA - Insert two new rows based on Userform criteria and also copying the excel formula of a cell range

分類Dev

Move value from one UserForm to another (variable) UserForm

分類Dev

Userform listbox that depends on another listbox

分類Dev

Userform QueryClose Will only Work Once

分類Dev

VBA-この状況でループを適用する方法(Userform.Combox ...)?

分類Dev

Is it possible to create and handle a custom Event in a Customized UserForm?

分類Dev

Userform Timestamp Cell When textbox Update

Related 関連記事

  1. 1

    UserForm ComboBox

  2. 2

    VBA UserForm label in spreadsheet

  3. 3

    sql source for a vba userform

  4. 4

    How do I call a module from my userform in vba?

  5. 5

    Chosen result from Worksheet cell to Userform Combobox

  6. 6

    VBA - destroy a modeless UserForm instance properly

  7. 7

    Excel VBA UserForm printscreen save as pdf

  8. 8

    Double click event in the excel sheet column to fill all textboxes of a Userform

  9. 9

    Excel UserForm button click slow response time when clicked fast

  10. 10

    VBA Entering userform data at next blank row correctly

  11. 11

    Excel VBA Userform Listbox Dynamic Context Menu Using .OnAction Method

  12. 12

    VBA USERFORMエラー6の回避策

  13. 13

    Update a userform listbox after userform initialization

  14. 14

    Auto Size/Adjust Userform

  15. 15

    Conflict bewteen OLEObjects and Userform

  16. 16

    Put variable in UserForm name

  17. 17

    Self Adjusting Userform Size

  18. 18

    Userform not copying data to spreadsheet

  19. 19

    vba userform , if any of the checkboxes in the frame is true then macro should not be applied on the sheetname mentioned in the checkbox

  20. 20

    VBA: How to change default selection on a Userform & restrict user from texting values under a dropdown column

  21. 21

    Excel VBA:USerform P&Lが列に入力されました

  22. 22

    VBA -How to properly Find, Copy and Paste a Search from a Command Button on a Userform?

  23. 23

    VBA - Insert two new rows based on Userform criteria and also copying the excel formula of a cell range

  24. 24

    Move value from one UserForm to another (variable) UserForm

  25. 25

    Userform listbox that depends on another listbox

  26. 26

    Userform QueryClose Will only Work Once

  27. 27

    VBA-この状況でループを適用する方法(Userform.Combox ...)?

  28. 28

    Is it possible to create and handle a custom Event in a Customized UserForm?

  29. 29

    Userform Timestamp Cell When textbox Update

ホットタグ

アーカイブ