trying_to_learn_coding
New Member
- Joined
- Jun 22, 2023
- Messages
- 12
- Office Version
- 2019
- Platform
- Windows
HELLO GUYS, I NEED HELP.
my code is something like this,
i write this code for every comboboxes im using, so lets say i have 20 comboboxes, then i copy/paste this code for everyone of them. and also if there are a lot of TEXTLEGENDTEST.values, like 20 of them, its so time consuming to edit in each comboboxes and a lot of lines of codes.
it is working by the way but maybe there are more other options and make it short, look neat.
thank you
my code is something like this,
VBA Code:
If CMBCHEMLABEL1.value= TEXTLEGENDTEST1 Then
Sheets("chem").Shapes("SHLABEL1").TextFrame2.TextRange.Characters.Text = CMBCHEMLABEL1.value
Sheets("chem").Shapes("SHTEST1").TextFrame2.TextRange.Characters.Text = TXTCHEMTEST1.value
Sheets("chem").Shapes("SHNVUNIT1").TextFrame2.TextRange.Characters.Text = TEXTLEGUNIT1.value
Sheets("chem").Shapes("SHNVM1").TextFrame2.TextRange.Characters.Text = TEXTLEGRRM1.value
Sheets("chem").Shapes("SHNVF1").TextFrame2.TextRange.Characters.Text = TEXTLEGRRF1.value
Sheets("chem").Shapes("SHNVCH1").TextFrame2.TextRange.Characters.Text = TEXTLEGRRCH1.value
ElseIf CMBCHEMLABEL1.value= TEXTLEGENDTEST2 Then
Sheets("chem").Shapes("SHLABEL1").TextFrame2.TextRange.Characters.Text = CMBCHEMLABEL1.value
Sheets("chem").Shapes("SHTEST1").TextFrame2.TextRange.Characters.Text = TXTCHEMTEST1.value
Sheets("chem").Shapes("SHNVUNIT1").TextFrame2.TextRange.Characters.Text = TEXTLEGUNIT2.value
Sheets("chem").Shapes("SHNVM1").TextFrame2.TextRange.Characters.Text = TEXTLEGRRM2.value
Sheets("chem").Shapes("SHNVF1").TextFrame2.TextRange.Characters.Text = TEXTLEGRRF2.value
Sheets("chem").Shapes("SHNVCH1").TextFrame2.TextRange.Characters.Text = TEXTLEGRRCH2.value
ElseIf CMBCHEMLABEL1.value= TEXTLEGENDTEST3 Then
Sheets("chem").Shapes("SHLABEL1").TextFrame2.TextRange.Characters.Text = CMBCHEMLABEL1.value
Sheets("chem").Shapes("SHTEST1").TextFrame2.TextRange.Characters.Text = TXTCHEMTEST1.value
Sheets("chem").Shapes("SHNVUNIT1").TextFrame2.TextRange.Characters.Text = TEXTLEGUNIT3.value
Sheets("chem").Shapes("SHNVM1").TextFrame2.TextRange.Characters.Text = TEXTLEGRRM3.value
Sheets("chem").Shapes("SHNVF1").TextFrame2.TextRange.Characters.Text = TEXTLEGRRF3.value
Sheets("chem").Shapes("SHNVCH1").TextFrame2.TextRange.Characters.Text = TEXTLEGRRCH3.value
ElseIf CMBCHEMLABEL1.value= TEXTLEGENDTEST4 Then
Sheets("chem").Shapes("SHLABEL1").TextFrame2.TextRange.Characters.Text = CMBCHEMLABEL1.value
Sheets("chem").Shapes("SHTEST1").TextFrame2.TextRange.Characters.Text = TXTCHEMTEST1.value
Sheets("chem").Shapes("SHNVUNIT1").TextFrame2.TextRange.Characters.Text = TEXTLEGUNIT4.value
Sheets("chem").Shapes("SHNVM1").TextFrame2.TextRange.Characters.Text = TEXTLEGRRM4.value
Sheets("chem").Shapes("SHNVF1").TextFrame2.TextRange.Characters.Text = TEXTLEGRRF4.value
Sheets("chem").Shapes("SHNVCH1").TextFrame2.TextRange.Characters.Text = TEXTLEGRRCH4.value
'more and more like this until i reach
ElseIf CMBCHEMLABEL1.value= TEXTLEGENDTEST20 Then
Sheets("chem").Shapes("SHLABEL1").TextFrame2.TextRange.Characters.Text = CMBCHEMLABEL1.value
Sheets("chem").Shapes("SHTEST1").TextFrame2.TextRange.Characters.Text = TXTCHEMTEST1.value
Sheets("chem").Shapes("SHNVUNIT1").TextFrame2.TextRange.Characters.Text = TEXTLEGUNIT20.value
Sheets("chem").Shapes("SHNVM1").TextFrame2.TextRange.Characters.Text = TEXTLEGRRM20.value
Sheets("chem").Shapes("SHNVF1").TextFrame2.TextRange.Characters.Text = TEXTLEGRRF20.value
Sheets("chem").Shapes("SHNVCH1").TextFrame2.TextRange.Characters.Text = TEXTLEGRRCH20.value
End If
i write this code for every comboboxes im using, so lets say i have 20 comboboxes, then i copy/paste this code for everyone of them. and also if there are a lot of TEXTLEGENDTEST.values, like 20 of them, its so time consuming to edit in each comboboxes and a lot of lines of codes.
it is working by the way but maybe there are more other options and make it short, look neat.
thank you
Last edited by a moderator: