huppelpaard
Gebruiker
- Lid geworden
- 27 mei 2018
- Berichten
- 157
Beetje bij beetje kom ik steeds verder met automatisering en het werkt wel maar het is gewoon niet netjes.
hieronder een voorbeeldje wat mijn code is in een userform
zoals je ziet bij heel veel combo of text boxen moet ik steeds per combo/textbox aanpassen
nu ben ik een beetje aan het googlen en dan kom je ook methodes tegen om for each te gebruiken
echter is mijn kennis onvoldoende daarom hoop ik dat iemand mij op weg wilt helpen met wat uitleg hierover
kan je bovenstaande code korter maken? en hoe werkt dat dan?
hopelijk kan ik weer iets leren van jullie
alvast bedankt

hieronder een voorbeeldje wat mijn code is in een userform
Code:
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("An2")
TextBox10.Value = sheets("Hulpblad").Range("An3")
TextBox11.Value = sheets("Hulpblad").Range("An4")
TextBox12.Value = sheets("Hulpblad").Range("An5")
TextBox13.Value = sheets("Hulpblad").Range("An6")
TextBox14.Value = sheets("Hulpblad").Range("An7")
TextBox15.Value = sheets("Hulpblad").Range("An8")
TextBox16.Value = sheets("Hulpblad").Range("An9")
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"
If TextBox1.Value <> "" Then
ComboBox1.Value = "MINI"
Else
ComboBox1.Value = ""
End If
If TextBox2.Value <> "" Then
ComboBox2.Value = "MINI"
Else
ComboBox2.Value = ""
End If
If TextBox3.Value > -1 Then ComboBox3.Value = "MINI"
If TextBox4.Value > -1 Then ComboBox4.Value = "MINI"
If TextBox5.Value > -1 Then ComboBox5.Value = "MINI"
If TextBox6.Value > -1 Then ComboBox6.Value = "MINI"
If TextBox7.Value > -1 Then ComboBox7.Value = "MINI"
If TextBox8.Value > -1 Then ComboBox8.Value = "MINI"
If TextBox9.Value > -1 Then ComboBox9.Value = "MINI"
If TextBox10.Value > -1 Then ComboBox10.Value = "MINI"
If TextBox11.Value > -1 Then ComboBox11.Value = "MINI"
If TextBox12.Value > -1 Then ComboBox12.Value = "MINI"
If TextBox13.Value > -1 Then ComboBox13.Value = "MINI"
If TextBox14.Value > -1 Then ComboBox14.Value = "MINI"
If TextBox15.Value > -1 Then ComboBox15.Value = "MINI"
If TextBox16.Value > -1 Then ComboBox16.Value = "MINI"
zoals je ziet bij heel veel combo of text boxen moet ik steeds per combo/textbox aanpassen
nu ben ik een beetje aan het googlen en dan kom je ook methodes tegen om for each te gebruiken
echter is mijn kennis onvoldoende daarom hoop ik dat iemand mij op weg wilt helpen met wat uitleg hierover
kan je bovenstaande code korter maken? en hoe werkt dat dan?
hopelijk kan ik weer iets leren van jullie

alvast bedankt

Laatst bewerkt: