Live-Forum - Die aktuellen Beiträge
Datum
Titel
28.03.2024 21:12:36
28.03.2024 18:31:49
Anzeige
Archiv - Navigation
1064to1068
Aktuelles Verzeichnis
Verzeichnis Index
Übersicht Verzeichnisse
Vorheriger Thread
Rückwärts Blättern
Nächster Thread
Vorwärts blättern
Anzeige
HERBERS
Excel-Forum (Archiv)
20+ Jahre Excel-Kompetenz: Von Anwendern, für Anwender
Zahlen in Text umwandeln
01.04.2009 23:23:30
Thomas
Liebe Excelianer
Ich fülle per Excel ein Formular aus, welches ich anschliessend auf einen Check drucke. Darauf gibt es ein Feld mit einem Total, welches unten in Textform übertragen werden muss (Betrag in Worten).
Was kann ich tun, damit diese Zahl automatisch in Buchstaben umgewandelt wird?
Das Resultat sollte dann zB. so aussehen: acht-fünf /00 oder auch eins-acht-fünf /35
Ich habe meine Vorlage hochgeladen:
https://www.herber.de/bbs/user/60915.xls
Danke euch für die Hilfe!
Gruss
Thomas

15
Beiträge zum Forumthread
Beiträge zu diesem Forumthread

Betreff
Datum
Anwender
Anzeige
AW: Zahlen in Text umwandeln
02.04.2009 00:18:27
mike49
Hallo Thomas,
Schreibe die Function in ein neues Modul

Function inWorten$(wert$)
Const Blöcke = 4
'max Anzahl von Dreierblöcken in einer Zahl (z.B. 4 = max bis 999 999 999 999)
Dim Block$(Blöcke)
Dim text$(Blöcke)
Dim Gruppe$(Blöcke)
Dim GrEndSg$(Blöcke)
Dim GrEndPl$(Blöcke)
Dim Einer$(10)
Dim Einer2$(10)
Dim i%, pos%
Dim nk$, TextG$
Dim neg As String
If wert  0
wert$ = Left$(wert$, pos - 1) + Right$(wert$, Len(wert$) - pos)
pos = InStr(pos, wert$, ".")
Wend
'* Nachkommastellen NK$ schreiben
pos = InStr(wert$, ",")
If pos > 0 Then
nk$ = Right$(wert$, Len(wert$) - pos)
wert$ = Left$(wert$, pos - 1)
Else
nk$ = ""
End If
For i = 1 To Blöcke
If Len(wert$) > 3 Then
Block$(i) = Right$(wert$, 3)
wert$ = Left$(wert$, Len(wert$) - 3)
Else
Block$(i) = wert$
wert$ = ""
End If
If Block$(i)  "" Then
If Len(Block$(i)) = 3 Then
If Block$(i) = "000" Then
text$(i) = ""
ElseIf Left$(Block$(i), 1) = "1" Then
text$(i) = "einhundert"
ElseIf Left$(Block$(i), 1) = "0" Then
text$(i) = ""
Else
text$(i) = text$(i) + Einer$(Val(Left$(Block$(i), 1))) + "hundert"
End If
Block$(i) = Right$(Block$(i), 2)
End If
If Len(Block$(i)) = 2 Then
If Left$(Block$(i), 1) = "0" Then
text$(i) = text$(i) + Einer$(Val(Right$(Block$(i), 1)))
ElseIf Left$(Block$(i), 1) = "1" Then
If Left$(Block$(i), 2) = "11" Then
text$(i) = text$(i) + "elf"
ElseIf Left$(Block$(i), 2) = "12" Then
text$(i) = text$(i) + "zwölf"
Else
text$(i) = text$(i) + Einer2$(Val(Right$(Block$(i), 1))) + "zehn"
End If
ElseIf Left$(Block$(i), 1) = "2" Then
If Left$(Block$(i), 2) = "21" Then
text$(i) = text$(i) + "ein"
Else
text$(i) = text$(i) + Einer$(Val(Right$(Block$(i), 1)))
End If
If Left$(Block$(i), 2)  "20" Then
text$(i) = text$(i) + "und"
End If
text$(i) = text$(i) + "zwanzig"
ElseIf Left$(Block$(i), 1) = "3" Then
If Left$(Block$(i), 2) = "31" Then
text$(i) = text$(i) + "ein"
Else
text$(i) = text$(i) + Einer$(Val(Right$(Block$(i), 1)))
End If
If Left$(Block$(i), 2)  "30" Then
text$(i) = text$(i) + "und"
End If
text$(i) = text$(i) + "dreißig"
Else
If Right$(Block$(i), 1) = "1" Then
text$(i) = text$(i) + "ein"
Else
text$(i) = text$(i) + Einer$(Val(Right$(Block$(i), 1)))
End If
If Right$(Block$(i), 1)  "0" Then
text$(i) = text$(i) + "und"
End If
text$(i) = text$(i) + Einer2$(Val(Left$(Block$(i), 1))) + "zig"
End If
End If
If Len(Block$(i)) = 1 Then
text$(i) = text$(i) + Einer$(Val(Right$(Block$(i), 1)))
End If
End If
If text$(i)  "" Then
End If
Next
For i = Blöcke To 1 Step -1
If text$(i)  "" Then
If text$(i) = "eins" Then
If i > 2 Then
text$(i) = "eine"
ElseIf i = 2 Then
text$(i) = "ein"
End If
text$(i) = text$(i) + Gruppe$(i)
text$(i) = text$(i) + GrEndSg$(i)
Else
text$(i) = text$(i) + Gruppe$(i)
text$(i) = text$(i) + GrEndPl$(i)
End If
End If
TextG$ = TextG$ + text$(i)
Next
If TextG$ = "" Then
TextG$ = " "
End If
If (nk$  "") And (nk$  "0") And (nk$  "00") Then
If Len(nk$) = 1 Then
nk$ = nk$ + "0"
End If
TextG$ = "" + TextG$ + "  " + nk$ + "/100 "
End If
If Right$(TextG$, 1) = ")" Then
TextG$ = Left$(TextG$, 13) + Chr$(Asc(Mid$(TextG$, 14, 1)) - 32) + Right$(TextG$, Len(TextG$) -  _
14)
Else
TextG$ = Chr$(Asc(Left$(TextG$, 1)) - 32) + Right$(TextG$, Len(TextG$) - 1)
End If
inWorten$ = TextG$
End Function


Trage in die Zelle in der der Betrag in Worten stehen soll ein : =inWorten($J$16)
Vielleicht ist es das, was du suchst?
Gruß
mike49

Anzeige
AW: Zahlen in Text umwandeln
02.04.2009 00:28:49
Oberschlumpf
Hi Thomas
Und hier meine Idee (geht aber nur bis zu nem Betrag von max. 9999,99 - der Code ist abr problemlos erweiterbar)
https://www.herber.de/bbs/user/60916.xls
Hilfts?
Ciao
Thorsten
AW: Zahlen in Text umwandeln
02.04.2009 00:47:45
Thomas
Vielen Dank für die beiden Beiträge.
Mit der Verwendung des ersten wäre ich ehrlich gesagt etwas überfordert.
Der Zweite macht eigentlich genau das, was ich suche. Allerdings gibt es noch zwei Dinge:
1. Es erscheint ein Laufzeitfehler. Wie korrigiere ich den?
2. Ein kleiner Endbetrag benötigt keine führenden Nullen im Textteil. zB. null-null-sieben-fünf /25 (für 75.25. Kann man diese auch weglassen?
lieben Gruss
Thomas
Anzeige
AW: Zahlen in Text umwandeln
02.04.2009 07:47:24
Oberschlumpf
deine Anrede fehlt (und wenn's nur'n "Hallo" ist) - bitte darauf achten
Hi Thomas
Stimmt, führende Nullen machen keinen Sinn.
Und mir mir sind zwei weitere Fehler aufgefallen:
- das Calculate-Ereignis wird immer und immer wieder ausgeführt.
- bei einem Nullwert hinter dem Komma wird anstelle von /00 nur /0 ausgegeben
Lösch den alten Code und verwende diesen:

Sub sbZahlWort(ByVal betrag As Double)
Dim liVorKomma As Integer, li1000 As Integer, li100 As Integer, li10 As Integer
Application.EnableEvents = False
liVorKomma = Int(betrag)
If liVorKomma / 1000 > 1 Then
lstrZahlwort = fcUmwandel(lstrZahlwort & LTrim(Str(Int(liVorKomma / 1000)))) & "-"
liVorKomma = liVorKomma - Int(liVorKomma / 1000) * 1000
End If
If liVorKomma / 100 > 1 Then
lstrZahlwort = lstrZahlwort & fcUmwandel(LTrim(Str(Int(liVorKomma / 100)))) & "-"
liVorKomma = liVorKomma - Int(liVorKomma / 100) * 100
End If
If liVorKomma / 10 > 1 Then
lstrZahlwort = lstrZahlwort & fcUmwandel(LTrim(Str(Int(liVorKomma / 10)))) & "-"
liVorKomma = liVorKomma - Int(liVorKomma / 10) * 10
lstrZahlwort = lstrZahlwort & fcUmwandel(LTrim(Str(liVorKomma))) & " /" & Right( _
Format(betrag - Int(betrag), "00"), 2)
End If
Range("F26").Value = lstrZahlwort
Application.EnableEvents = True
End Sub


(Zeilenumbrüche, die hier im Code angezeigt werden, bitte nicht übernehmen)
Deinen Hinweis "Es erscheint ein Laufzeitfehler" finde ich, ehrlich gesagt - nicht - hilfreich.
Denn wie soll ich von hier aus erkennen, wie wo wann warum dieser Fehler erscheint, wenn du es mir nicht aufschreibst?!!?
Aber vielleicht ist mit dem neuen Code auch der Laufzeitfehler verschwunden.
Wenn nicht, dann bitte eine so genaue Beschreibung des Fehlers, dass auch derjenige verstehen kann, der nicht mit vor deinem PC sitzt - am besten wäre natürlich, wenn du eine Bsp-Datei zeigst, in der dieser Fehler auftritt.
Funktioniert denn nun alles?
Ciao
Thorsten

Anzeige
Korrektur
02.04.2009 08:10:18
Oberschlumpf
Hi Thomas
Hab wieder einen Fehler gefunden.
Tausch die entsprechende Codezeile aus gegen diese:

lstrZahlwort = lstrZahlwort & fcUmwandel(LTrim(Str(liVorKomma))) & " /" & Right(Format(betrag - Round(betrag, 0), "0.00"), 2)


Du findest sie im "If liVorKomma / 10 > 1 Then"-Block.
Nun sollte aber alles funktionieren, oder?
Ciao
Thorsten

nix VBA: da reichen doch zwei Formeln
02.04.2009 10:25:36
WF
Hi Thomas,
die umzuwandelnde Zahl steht in A1.
in A3 (Hilfszelle) steht:
=WECHSELN(WECHSELN(WECHSELN(WECHSELN(WECHSELN(WECHSELN(WECHSELN(GANZZAHL(A1);0;"null ");1;"eins ");2; "zwo ");3;"drei ");4;"vier ");5;"fünf ");6;"sechs ")
das Ergebnis dann irgendwo:
=WECHSELN(WECHSELN(WECHSELN(A3;7;"sieben ");8;"acht ");9;"neun ")&"/"&TEXT(100*REST(A1;1);"00")
willst Du die Bindestriche sehen, dann in A3:
=WECHSELN(WECHSELN(WECHSELN(WECHSELN(WECHSELN(WECHSELN(WECHSELN(GANZZAHL(A1);0;"null-");1;"eins-");2; "zwo-");3;"drei-");4;"vier-");5;"fünf-");6;"sechs-")
und als Ergebnis:
=WECHSELN(WECHSELN(WECHSELN(WECHSELN(A3;7;"sieben-");8;"acht-");9;"neun-");"-";" /"; LÄNGE(GANZZAHL(A1)))&TEXT(100*REST(A1;1);"00")
- ist etwas länger, da der letzte Bindestrich ja eliminiert werden muss.
Salut WF
Anzeige
AW: nix VBA: da reichen doch zwei Formeln
02.04.2009 14:52:52
thomas
Vielen Dank für eure super Hilfe!
Mit dem letzten "nix VBA Vorschlag" bin ich sofort zurecht gekommen. Bei den komplizierten Varianten blicke ich einfach nicht immer durch :-(
Teste es noch kurz in allen Varianten und dann dürfen meine Mitarbeiter länger voraussichtlich Kaffee trinken!
Gruss Thomas
AW: nix VBA: da reichen doch zwei Formeln
02.04.2009 16:18:31
Höttl
Hallo!
Habe das gefunden, passt das?
Tabelle1

 ABCDE
12178,45zweitausendeinhundertachtundsiebzig und 45/100   
212,89zwölf und 89/100   
312zwölf   
478,99achtundsiebzig und 99/100   

Formeln der Tabelle
ZelleFormel
B1=inworten(A1)
B2=inworten(A2)
B3=inworten(A3)
B4=inworten(A4)


Excel Tabellen im Web darstellen >> Excel Jeanie HTML 4
  • 
    Function inWorten$(wert$)
    Const Blöcke = 4
    'max Anzahl von Dreierblöcken in einer Zahl (z.B. 4 = max bis 999 999 999 999)
    Dim Block$(Blöcke)
    Dim Text$(Blöcke)
    Dim Gruppe$(Blöcke)
    Dim GrEndSg$(Blöcke)
    Dim GrEndPl$(Blöcke)
    Dim Einer$(10)
    Dim Einer2$(10)
    Einer$(0) = ""
    Einer$(1) = "eins"
    Einer$(2) = "zwei"
    Einer$(3) = "drei"
    Einer$(4) = "vier"
    Einer$(5) = "fünf"
    Einer$(6) = "sechs"
    Einer$(7) = "sieben"
    Einer$(8) = "acht"
    Einer$(9) = "neun"
    Einer2$(0) = ""
    Einer2$(1) = "ein"
    Einer2$(2) = "zwei"
    Einer2$(3) = "drei"
    Einer2$(4) = "vier"
    Einer2$(5) = "fünf"
    Einer2$(6) = "sech"
    Einer2$(7) = "sieb"
    Einer2$(8) = "acht"
    Einer2$(9) = "neun"
    Gruppe$(1) = ""
    Gruppe$(2) = "tausend"
    Gruppe$(3) = " Million"
    Gruppe$(4) = " Milliarde"
    ' Gruppenendung Singular
    GrEndSg$(1) = ""
    GrEndSg$(2) = ""
    GrEndSg$(3) = " "
    GrEndSg$(4) = " "
    ' Gruppenendung Plural
    GrEndPl$(1) = ""
    GrEndPl$(2) = ""
    GrEndPl$(3) = "en "
    GrEndPl$(4) = "n "
    For i = 1 To Blöcke
    Block$(i) = ""
    Text$(i) = ""
    Next
    '* Alle Punkte entfernen
    pos = InStr(wert$, ".")
    While pos > 0
    wert$ = Left$(wert$, pos - 1) + Right$(wert$, Len(wert$) - pos)
    pos = InStr(pos, wert$, ".")
    Wend
    '* Nachkommastellen NK$ schreiben
    pos = InStr(wert$, ",")
    If pos > 0 Then
    NK$ = Right$(wert$, Len(wert$) - pos)
    wert$ = Left$(wert$, pos - 1)
    Else
    NK$ = ""
    End If
    For i = 1 To Blöcke
    If Len(wert$) > 3 Then
    Block$(i) = Right$(wert$, 3)
    wert$ = Left$(wert$, Len(wert$) - 3)
    Else
    Block$(i) = wert$
    wert$ = ""
    End If
    If Block$(i)  "" Then
    If Len(Block$(i)) = 3 Then
    If Block$(i) = "000" Then
    Text$(i) = ""
    ElseIf Left$(Block$(i), 1) = "1" Then
    Text$(i) = "einhundert"
    ElseIf Left$(Block$(i), 1) = "0" Then
    Text$(i) = ""
    Else
    Text$(i) = Text$(i) + Einer$(Val(Left$(Block$(i), 1))) + "hundert"
    End If
    Block$(i) = Right$(Block$(i), 2)
    End If
    If Len(Block$(i)) = 2 Then
    If Left$(Block$(i), 1) = "0" Then
    Text$(i) = Text$(i) + Einer$(Val(Right$(Block$(i), 1)))
    ElseIf Left$(Block$(i), 1) = "1" Then
    If Left$(Block$(i), 2) = "11" Then
    Text$(i) = Text$(i) + "elf"
    ElseIf Left$(Block$(i), 2) = "12" Then
    Text$(i) = Text$(i) + "zwölf"
    Else
    Text$(i) = Text$(i) + Einer2$(Val(Right$(Block$(i), 1))) + "zehn"
    End If
    ElseIf Left$(Block$(i), 1) = "2" Then
    If Left$(Block$(i), 2) = "21" Then
    Text$(i) = Text$(i) + "ein"
    Else
    Text$(i) = Text$(i) + Einer$(Val(Right$(Block$(i), 1)))
    End If
    If Left$(Block$(i), 2)  "20" Then
    Text$(i) = Text$(i) + "und"
    End If
    Text$(i) = Text$(i) + "zwanzig"
    ElseIf Left$(Block$(i), 1) = "3" Then
    If Left$(Block$(i), 2) = "31" Then
    Text$(i) = Text$(i) + "ein"
    Else
    Text$(i) = Text$(i) + Einer$(Val(Right$(Block$(i), 1)))
    End If
    If Left$(Block$(i), 2)  "30" Then
    Text$(i) = Text$(i) + "und"
    End If
    Text$(i) = Text$(i) + "dreißig"
    Else
    If Right$(Block$(i), 1) = "1" Then
    Text$(i) = Text$(i) + "ein"
    Else
    Text$(i) = Text$(i) + Einer$(Val(Right$(Block$(i), 1)))
    End If
    If Right$(Block$(i), 1)  "0" Then
    Text$(i) = Text$(i) + "und"
    End If
    Text$(i) = Text$(i) + Einer2$(Val(Left$(Block$(i), 1))) + "zig"
    End If
    End If
    If Len(Block$(i)) = 1 Then
    Text$(i) = Text$(i) + Einer$(Val(Right$(Block$(i), 1)))
    End If
    End If
    If Text$(i)  "" Then
    End If
    Next
    For i = Blöcke To 1 Step -1
    If Text$(i)  "" Then
    If Text$(i) = "eins" Then
    If i > 2 Then
    Text$(i) = "eine"
    ElseIf i = 2 Then
    Text$(i) = "ein"
    End If
    Text$(i) = Text$(i) + Gruppe$(i)
    Text$(i) = Text$(i) + GrEndSg$(i)
    Else
    Text$(i) = Text$(i) + Gruppe$(i)
    Text$(i) = Text$(i) + GrEndPl$(i)
    End If
    End If
    TextG$ = TextG$ + Text$(i)
    Next
    If TextG$ = "" Then
    TextG$ = "null"
    End If
    If (NK$  "") And (NK$  "0") And (NK$  "00") Then
    If Len(NK$) = 1 Then
    NK$ = NK$ + "0"
    End If
    TextG$ = TextG$ + " und " + NK$ + "/100"
    End If
    ' TextG$ = Chr$(Asc(Left$(TextG$, 1)) - 32) + Right$(TextG$, Len(TextG$) - 1)
    inWorten$ = TextG$
    End Function
    



  • Gruß
    Wilfried
    Anzeige
    AW: Zahlen in Text umwandeln
    02.04.2009 18:31:24
    Höttl
    Hallo WF!
    Recht hast Du, habe das überlesen.
    Hier mit Deiner Formel
    Tabelle1

     ABC
    185,12  
    2   
    38fünf acht fünf /12

    Formeln der Tabelle
    ZelleFormel
    A3=WECHSELN(WECHSELN(WECHSELN(WECHSELN(WECHSELN(WECHSELN(WECHSELN(GANZZAHL(A1); 0;"null "); 1;"eins "); 2; "zwo "); 3;"drei "); 4;"vier "); 5;"fünf "); 6;"sechs ")
    B3=WECHSELN(WECHSELN(WECHSELN(A3;7;"sieben "); 8;"acht "); 9;"neun ")&"/"&TEXT(100*REST(A1;1); "00")


    Excel Tabellen im Web darstellen >> Excel Jeanie HTML 4
    Gruß
    Wilfried
    Anzeige
    AW: Zahlen in Text umwandeln
    03.04.2009 11:29:34
    Thomas
    Hallo Wilfried
    habe verschiedene Varianten gesucht wie ich deine Darstellung noch perfektionieren könnte. Folgendes habe ich für 258.50 gesucht:
    zwei-fünf-acht 50/100
    also: jeweils einen Bindestrich ausser bei der letzten Zahl. Zudem versuchte ich, nach dem "50" noch einen slash mit "100" einzufügen, als nicht variabler Bestandteil.
    Ich habe es nicht herausgefunden. Weisst du Rat?
    Gruss
    Thomas
    steht doch exakt in meinem Beitrag: nix VBA
    03.04.2009 11:37:56
    WF
    Variante 2
    AW: Zahlen in Text umwandeln
    03.04.2009 11:48:17
    Thomas
    Hi WF
    Das muss ich übersehen haben, sorry.
    Die Ergänzung mit dem /100 habe ich allerdings nicht gefunden. Wo in der Formel muss ich das einfügen?
    Gruss Thomas
    Anzeige
    /100 hab wiederum ich übersehen
    03.04.2009 12:14:30
    WF
    Hi Thomas,
    =WECHSELN(WECHSELN(WECHSELN(WECHSELN(A3;7;"sieben-");8;"acht-");9;"neun-");"-";" "; LÄNGE(GANZZAHL(A1)))&TEXT(REST(A1;1);"00/100")
    bzw. wenn Du bei glatten Zahlen hinten nicht 00/100 sehen willst:
    =WECHSELN(WECHSELN(WECHSELN(WECHSELN(A3;7;"sieben-");8;"acht-");9;"neun-");"-";" "; LÄNGE(GANZZAHL(A1)))&WENN(REST(A1;1)>0;TEXT(REST(A1;1);"00/100");"")
    Salut WF
    Perfekt!
    03.04.2009 12:18:32
    Thomas
    Hallo Wilfried
    Perfekt, DAS ist es!
    Super und vielen herzlichen Dank für deine Hilfe!
    Gruss Thomas

    420 Forumthreads zu ähnlichen Themen

    Anzeige
    Anzeige
    Anzeige

    Beliebteste Forumthreads (12 Monate)

    Anzeige

    Beliebteste Forumthreads (12 Monate)

    Anzeige
    Anzeige
    Anzeige