Könnt ihr mir auf die sprünge helfen und einen tipp geben.
Ich möchte 8 textboxen textbox2-textbox9 aufsteigend sortieren.
Die textboxen enthalten zahlen.
gruß sonja
' **********************************************************************
' Modul: UserForm1 Typ: Userform
' **********************************************************************
Option Explicit
Private Sub CommandButton1_Click()
Dim lngIndex As Long, dblValues(8) As Double
For lngIndex = 2 To 9
dblValues(lngIndex - 2) = TBValue(Controls("Textbox" & lngIndex).Value)
Next
For lngIndex = 2 To 9
Controls("Textbox" & lngIndex) = Application.Small(dblValues, lngIndex - 1)
Next
End Sub
Private Function TBValue(ByVal Value As Variant, Optional forceNumeric As Boolean = True, Optional CleanText As String = "") As Variant
On Error GoTo ExitFunction
If Len(CleanText) Then
Value = Trim(Replace(Value, CleanText, ""))
End If
If Len(Value) Then
If IsDate(Value) And Len(Value) >= 8 Then
Value = CDbl(CDate(Value))
ElseIf IsNumeric(Value) Then
Value = CDbl(Value)
End If
End If
TBValue = Value
ExitFunction:
If Not IsNumeric(TBValue) And forceNumeric Then TBValue = 0
End Function
' **********************************************************************
' Modul: UserForm1 Typ: Userform
' **********************************************************************
Option Explicit
Private Sub CommandButton1_Click()
Dim lngIndex As Long, dblValues(7) As Double
For lngIndex = 2 To 9
dblValues(lngIndex - 2) = TBValue(Controls("Textbox" & lngIndex).Value)
Next
For lngIndex = 2 To 9
Controls("Textbox" & lngIndex) = Application.Small(dblValues, lngIndex - 1)
Next
End Sub
Private Function TBValue(ByVal Value As Variant, Optional forceNumeric As Boolean = True, Optional CleanText As String = "") As Variant
On Error GoTo ExitFunction
If Len(CleanText) Then
Value = Trim(Replace(Value, CleanText, ""))
End If
If Len(Value) Then
If IsDate(Value) And Len(Value) >= 8 Then
Value = CDbl(CDate(Value))
ElseIf IsNumeric(Value) Then
Value = CDbl(Value)
End If
End If
TBValue = Value
ExitFunction:
If Not IsNumeric(TBValue) And forceNumeric Then TBValue = 0
End Function