M
m.s.w
Hi !
I try to learn how to write macros in excel. This is my first macro. I
have one problem. In a sheet I have few ComboBoxes which have
ListFillRange defined as an range of cells in another sheet (in the same
Workbook).
What i want to do is to check if the current value in ComboBox is a
value from the ListFillRange. If not, then it should be corrected.
Procedure is:
Sub Popraw_Wartosc(X As Object)
Dim K As Integer
Dim ItFits As Boolean
Dim Ilosc As Integer
ItFits = False
Ilosc = X.ListCount
For K = 0 To Ilosc - 1
If X.Value = X.List(K) Then
ItFits = True
End If
Next
If ItFits = False Then
X.Value = X.List(Ilosc - 1)
End If
End Sub
The problem is, that even if the current value of COmboBox has a
correspodning value in X.List, the "ItFits" variable never is true.
I try to watch this process, and on some stage I can read that X.Value
is lets say 1200, and the X.List(K) is also 1200 , but "ItFits" is still
False.
What am I missing?
Best Regards,
m.s.w
I try to learn how to write macros in excel. This is my first macro. I
have one problem. In a sheet I have few ComboBoxes which have
ListFillRange defined as an range of cells in another sheet (in the same
Workbook).
What i want to do is to check if the current value in ComboBox is a
value from the ListFillRange. If not, then it should be corrected.
Procedure is:
Sub Popraw_Wartosc(X As Object)
Dim K As Integer
Dim ItFits As Boolean
Dim Ilosc As Integer
ItFits = False
Ilosc = X.ListCount
For K = 0 To Ilosc - 1
If X.Value = X.List(K) Then
ItFits = True
End If
Next
If ItFits = False Then
X.Value = X.List(Ilosc - 1)
End If
End Sub
The problem is, that even if the current value of COmboBox has a
correspodning value in X.List, the "ItFits" variable never is true.
I try to watch this process, and on some stage I can read that X.Value
is lets say 1200, and the X.List(K) is also 1200 , but "ItFits" is still
False.
What am I missing?
Best Regards,
m.s.w