0 - Large
1 - Medium
2 - Small
(This assumes that the options are ordered in this way in your ComboBox)
0 - Large
1 - Medium
2 - Small
(This assumes that the options are ordered in this way in your ComboBox)
0 - Large
1 - Medium
2 - Small
(This assumes that the options are ordered in this way in your ComboBox)
It looklooks like using ListIndex
could cut down your code considerably, however this may reduce the readability of your code, and you may need to reorder the options in the ComboBox
or where the data is saved.
TheIt's the same one line of code, only thing changed here is the name of the ComboBox
has been changed, pretty simple stuff.
It look like using ListIndex
could cut down your code considerably, however this may reduce the readability of your code, and you may need to reorder the options in the ComboBox
or where the data is saved.
The only thing changed here is the name of the ComboBox
, pretty simple stuff.
It looks like using ListIndex
could cut down your code considerably, however this may reduce the readability of your code, and you may need to reorder the options in the ComboBox
or where the data is saved.
It's the same one line of code, only the name of the ComboBox
has been changed, pretty simple stuff.
It look like using ListIndex
could cut down your code considerably, however this may reduce the readability of your code, and you may need to reorder the options in the ComboBox
or where the data is saved.
Select Case Me.ComboBoxOffset.Value
Case "Large"
Cells(ActiveCell.Row, Range(RangeName).Column).Value = "ü"
Case "Medium"
Cells(ActiveCell.Row, Range(RangeName).Column).Offset(0, 1).Value = "ü"
Case "Small"
Cells(ActiveCell.Row, Range(RangeName).Column).Offset(0, 2).Value = "ü"
Case Else
End Select
By using ListIndex
you could cut this function down to:
Cells(ActiveCell.Row, Range(RangeName).Column).Offset(0, ComboBoxOffset.ListIndex).Value = "ü"
ListIndex
returns the index number of the option selected, in this case:
0 - Large
1 - Medium
2 - Small
(This assumes that the options are ordered in this way in your ComboBox)
Note how the index begins at 0 like Arrays
, this is useful in your case as your first option "Large" requires no Offset
. By using ListIndex
within Offset
the option "Large" is effectively Offset(0, 0)
, in other words no offset is made, and so you don't need to write an If
statement to handle the first option exclusively.
Select Case Me.ComboBoxConcept.Value
Case "Review"
Cells(ActiveCell.Row, Range(RangeName).Column).Value = "ü"
Case "Large"
Cells(ActiveCell.Row, Range(RangeName).Column).Offset(0, 1).Value = "ü"
Case "Medium"
Cells(ActiveCell.Row, Range(RangeName).Column).Offset(0, 2).Value = "ü"
Case "Small"
Cells(ActiveCell.Row, Range(RangeName).Column).Offset(0, 3).Value = "ü"
Case Else
End Select
So how could we use ListIndex
to reduce this one? Well...
Cells(ActiveCell.Row, Range(RangeName).Column).Offset(0, ComboBoxConcept.ListIndex).Value = "ü"
The only thing changed here is the name of the ComboBox
, pretty simple stuff.
Potential issue
Something to note with ListIndex
is that if no option has been selected in the ComboBox, ListIndex
will return a value of -1. This is an issue in your case as the offset will be (0, -1), meaning it will write in a column it shouldn't.
The easiest way to get around this is to check that an option has been selected before changing any cell values:
If ComboBoxOffset.ListIndex <> -1 then
Cells(ActiveCell.Row, Range(RangeName).Column).Offset(0, ComboBoxOffset.ListIndex).Value = "ü"
End If