AW: listindex problem bei combobox
17.07.2006 21:44:27
Christoph
Hallo Selo,
wie Chris schon sagte: der Fehler tritt auf, wenn die Zellen für Start und End-Wert nicht als Datum formatiert sind. Hinzu kommt, das Excel intern auch nicht mit Datumswerten rechnet sondern mit einer Ganzzahl (Anzahl Tage seit 1900).
probier mir das folgende, und gib mir Bescheid
Gruß Christoph
Option Explicit
Dim lngStartRow As Long
Private Sub ComboBox1_Change()
Me.TextBox1 = ThisWorkbook.Sheets(1).Cells(Me.ComboBox1.ListIndex + lngStartRow, 9)
End Sub
Private Sub UserForm_Activate()
Dim lngStartDat As Long, lngEndDat As Long
Dim lngEndRow As Long
Dim varVgl As Variant
With ThisWorkbook.Sheets(1)
'prüfe Anfangs- und End-Wert:
lngStartRow = 0
If Not IsDate(.Cells(1, 13)) Or Not IsDate(.Cells(2, 13)) Then
MsgBox "keine Datumswerte bei Start- bzw. End-Datum gegeben!"
Exit Sub
End If
'Anfangs- und End-Datum bestimmen:
lngStartDat = CLng(CDate(.Cells(1, 13)))
lngEndDat = CLng(CDate(.Cells(2, 13)))
varVgl = Application.Match(lngStartDat, .Columns(1), 0)
If Not IsError(varVgl) Then lngStartRow = CLng(varVgl)
varVgl = Application.Match(lngEndDat, .Columns(1), 0)
If Not IsError(varVgl) Then lngEndRow = CLng(varVgl)
'Fehlerabfangung:
If lngStartRow = 0 Or lngEndRow = 0 Then
MsgBox "Start- bzw. End-Datum nicht gegeben!"
Exit Sub
End If
If lngEndRow <= lngStartRow Then
MsgBox "End-Datum muss größer Start-Datum sein!"
Exit Sub
End If
'ComboBox füllen:
Me.ComboBox1.Clear
Me.ComboBox1.List = _
.Range(.Cells(lngStartRow, 1), .Cells(lngEndRow, 1)).Value
End With
End Sub