userform auto fill all

xassnake

New Member
Joined
Aug 13, 2023
Messages
1
Office Version
  1. 2019
Platform
  1. Windows
Hi,

I want to know how to auto fill my dropdown menu without putting 16 lines in my userform code
my goal is:
when the textboxes are filled my standard value = MINI

How can i do this?

below you can see my code is a little bitt messy
if you have a shorter code please advise :)

Private Sub UserForm_Initialize()

TextBox1.Value = sheets("Hulpblad").Range("ak2")
TextBox2.Value = sheets("Hulpblad").Range("ak3")
TextBox3.Value = sheets("Hulpblad").Range("ak4")
TextBox4.Value = sheets("Hulpblad").Range("ak5")
TextBox5.Value = sheets("Hulpblad").Range("ak6")
TextBox6.Value = sheets("Hulpblad").Range("ak7")
TextBox7.Value = sheets("Hulpblad").Range("ak8")
TextBox8.Value = sheets("Hulpblad").Range("ak9")
TextBox9.Value = sheets("Hulpblad").Range("AM2")
TextBox10.Value = sheets("Hulpblad").Range("AM3")
TextBox11.Value = sheets("Hulpblad").Range("AM4")
TextBox12.Value = sheets("Hulpblad").Range("AM5")
TextBox13.Value = sheets("Hulpblad").Range("AM6")
TextBox14.Value = sheets("Hulpblad").Range("AM7")
TextBox15.Value = sheets("Hulpblad").Range("AM8")
TextBox16.Value = sheets("Hulpblad").Range("AM9")

ComboBox1.Value = "MINI"
ComboBox9.Value = "MINI"
''Me.ComboBox1.List = Worksheets("HULPBLAD").Range("Type_kabel")
''Me.ComboBox1.RowSource = Worksheets("HULPBLAD").Range("Type_kabel").Address(external:=True)
Me.ComboBox1.RowSource = "Type_kabel"
Me.ComboBox2.RowSource = "Type_kabel"
Me.ComboBox3.RowSource = "Type_kabel"
Me.ComboBox4.RowSource = "Type_kabel"
Me.ComboBox5.RowSource = "Type_kabel"
Me.ComboBox6.RowSource = "Type_kabel"
Me.ComboBox7.RowSource = "Type_kabel"
Me.ComboBox8.RowSource = "Type_kabel"
Me.ComboBox9.RowSource = "Type_kabel"
Me.ComboBox10.RowSource = "Type_kabel"
Me.ComboBox11.RowSource = "Type_kabel"
Me.ComboBox12.RowSource = "Type_kabel"
Me.ComboBox13.RowSource = "Type_kabel"
Me.ComboBox14.RowSource = "Type_kabel"
Me.ComboBox15.RowSource = "Type_kabel"
Me.ComboBox16.RowSource = "Type_kabel"




End Sub
 

Attachments

  • 1691969802632.png
    1691969802632.png
    8.9 KB · Views: 13

Excel Facts

Excel Can Read to You
Customize Quick Access Toolbar. From All Commands, add Speak Cells or Speak Cells on Enter to QAT. Select cells. Press Speak Cells.
Where you have groups with consecutive values (e.g. Textbox1, Textbox2, etc.) you can loop in a manner like this:
VBA Code:
Dim i As Integer
Dim str As String

For i = 1 To 8
   str = sheets("Hulpblad").Range("ak" & i+1)
   Sheets("4").oleobjects("Textbox" & i).object.text = str
Next
You will need another loop after the first one to deal with numbers 9 to 16.
Note: that code is for an activeX textbox on a sheet. It wasn't until I got the reference syntax correct that I noticed yours are on a userform. I concentrated on the block of code lines and your desire to condense and I overlooked that. So don't copy verbatim but follow the logic instead. Doing this on a userform should be easier. You would use your own sheet name of course.
 
Upvote 0

Forum statistics

Threads
1,223,894
Messages
6,175,252
Members
452,623
Latest member
Techenthusiast

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