Option
Explicit
Private
Sub
ComboBox_Change()
Call
Berechnen
End
Sub
Private
Sub
txtGramm_Change()
Call
Berechnen
End
Sub
Private
Sub
Berechnen()
Dim
lngIndex
As
Long
Dim
txtLebensmittel
As
String
Dim
lngLetzteZeile
As
Long
lngLetzteZeile = Cells(Rows.Count, 1).
End
(xlUp).Row
txtLebensmittel = Cells(ComboBox.ListIndex + 2, 1)
On
Error
GoTo
ZahlReset
Me
.txtEiweiß =
Me
.txtGramm.Value * Application.VLookup(txtLebensmittel, Range(
"A2:C"
& lngLetzteZeile), 3,
False
)
Me
.txtKcal =
Me
.txtGramm.Value * Application.VLookup(txtLebensmittel, Range(
"A2:C"
& lngLetzteZeile), 2,
False
)
On
Error
GoTo
0
Exit
Sub
ZahlReset:
Me
.txtGramm.Value = 0
Me
.txtGramm.SelStart = 0
Me
.txtGramm.SelLength = Len(
Me
.txtGramm)
Resume
End
Sub