Hallo zusammen habe eine wunderschöne Funktion im Netz gefungen (danke dem Autor) die aber für mein Zwecke noch nicht ganz vollstädnig ist.
Die Funktion extrahiert Zahlen aus einer Textzelle und schreibt den Wert in eine andere Zelle. Da ich aber Straßennamen habe und diese auch einen unbedingt benötigten Buchstaben nach einer Hausnummer haben können würde ich mich freuen, wenn hier jemand die Funktion so abändern kann das alles, was nach den Zahlen kommt einfach stehen bleibt.
So sieht jetzt aus:
Zelle A1 = Meierstr. 1a-f
Funktion in Zelle B1:
=zahlA(a1) , Ergebnis = 1
Funktion in Zelle C1:
=zahlB(a1), Ergebnis = Meierstr. a-f
Korrekt sollte es aber heißen:
in B1 = 1a-f
in C1 = Meierstr.
-----------------------------------------------------------------------------------------------
Hier mal der Code:
'##############################################################################
' #############
'Zahl aus Text
Function ZahlAusText(Zelle As String) As Double
Dim i%, x As Boolean, Minus As Boolean, Komma As Boolean, Zahl$
x = False
Minus = False
Komma = False
Zahl = ""
For i = 1 To Len(Zelle)
If Mid(Zelle, i, 1) = "-" And IsNumeric(Mid(Zelle, i + 1, 1)) Then
If Minus = True Then GoTo Ende
Zahl = "-"
Minus = True
End If
If IsNumeric(Mid(Zelle, i, 1)) Or Mid(Zelle, i, 1) = "," Then
If Mid(Zelle, i, 1) = "," And Komma = True Then GoTo Ende
If Mid(Zelle, i, 1) = "," Then Komma = True
x = True
Zahl = Zahl & Mid(Zelle, i, 1)
End If
If Not IsNumeric(Mid(Zelle, i, 1)) And Mid(Zelle, i, 1) <> "," And x = _
True Then GoTo Ende
Next
Ende:
If Zahl = "" Then ZahlAusText = 0 Else ZahlAusText = CDbl(Zahl)
End Function
'Herausarbeiten der Zahl
Function ZahlA(Zelle As String) As Variant
Application.Volatile
For i = Len(Zelle) To 1 Step -1
If IsNumeric(Mid(Zelle, i, 1)) Then ZahlA = Mid(Zelle, i, 1) & ZahlA
Next
ZahlA = ZahlA * 1
If ZahlA = 0 Then ZahlA = ""
End Function
Function ZahlB(Zelle As String) As String
Application.Volatile
For i = 1 To Len(Zelle)
If Not IsNumeric(Mid(Zelle, i, 1)) Then
ZahlB = ZahlB & Mid(Zelle, i, 1)
End If
Next
End Function -------------------------------------------------------------------------------------------------
Hab schon einiges Erfolglos ausprobiert....
Danke euch |