online 1
gast (50)

/ Forum / Tabellenkalkulation

TabellenkalkulationTabellenkalkulation

Fragevon BenjaminM vom 29.10.2020, 12:05 Options

Lösung

Zahlen in Wörter, aber auf englisch!!!

Hallo,

Hab einiges im Netz zum Thema gefunden aber nicht richtig umsetzen können.
Doch nun hab ich eine Code von "Hofmann", der funzt, aber ich brauche den auf Englisch.
Habe den Code bereits angepasst, sprich die Wörter ins Englisch übersetzt.
Mein Problem ist aber das ich zwischen den Wörtern gerne ein Lehrzeichen hätte, und das bei z.B.
525 FIVE HUNDRED TWENTY FIVE ausgegeben wird.
Mit dem jetzigen Makro kommt
FIVEHUNDRETFIVEANDTWENTY raus.

Wie ändere ich das am besten, das ich Lehrzeichen dazwischen bekomme und das am Ende TWENTY FIVE steht (also richtig herrum).

Danke schonmal im Vorraus, und hier eben noch der Code

MfG Benjae
    Option Explicit

    Dim BisNINETEEN As Variant
    Dim TEEN As Variant
    Dim THAUSEND As Variant

    'In Anlehnung an eine Klassenprogrammierung von Hans W. Hofmann
    Function ZWort(dZahl As Double, Optional bln As Boolean)
    Dim dRest As Double
    dRest = WorksheetFunction.Round((dZahl - Fix(dZahl)), 2) * 100
    dZahl = Fix(dZahl)
    BisNINETEEN = Array("", "ONE", "TWO", "THREE", "FOUR", _
    "FIVE", "SIX", "SEVEN", "EIGHT", "NINE", "TEN", _
    "ELEVEN", "TWELVE", "THIRDTEEN", "FOURTEEN", "FIFTEEN", _
    "SIXTEEN", "SEVENTEEN", "EIGHTEEN", "NINETEEN")
    TEEN = Array("", "TEEN", "TWNETY", "THIRTY", _
    "FOURTY", "FIFTY", "SIXTY", "SEVENTY", _
    "EIGHTY", "NINETY")
    THAUSEND = Array("", "THAUSEND", "MILLION", "BILLION")
    If dRest = 0 Then
    ZWort = Text(dZahl)
    Else
    If bln Then
    ZWort = Text(dZahl) & " " & dRest & "/00"
    Else
    ZWort = Text(dZahl)
    End If
    End If
    End Function


    Private Function Wort(wert As Integer) As String
    Dim h As Integer
    h = wert Mod 100
    If h < 20 Then
    Wort = BisNINETEEN(h)
    Else
    Wort = BisNINETEEN(h Mod 10) & IIf(h Mod 10 > 0, "AND ", "") & _
    TEEN(Int(h / 10))
    End If
    h = (wert Mod 1000 - h) / 100
    If h > 0 Then Wort = BisNINETEEN(h) & "HUNDRED" & Wort
    End Function



    Private Function Text(wert As Double)
    Dim l As Integer, i As Integer, p As Integer
    If InStr(1, Str(wert), ",") = 0 And InStr(1, Str(wert), ".") = 0 Then
    For i = 1 To 1 + Int(Len(Str(wert)) / 3)
    p = Val("0" & Mid("000" + Str(wert), _
    Len("000" & Str(wert)) - i * 3 + 1, 3))
    If p > 0 Then Text = Wort(p) & THAUSEND(i - 1) & Text
    Next
    Else
    Text = "#Ganzzahl!"
    End If
    If Right(Text, 3) = "ein" Then Text = Text & "s"
    End Function



Antwort schreiben

Antwort 1 von coros vom 29.10.2020, 12:45 Options

Hallo Benjae,

ganz spontan würde mir einfallen, dass Du bei jedem Wort, das übersetzt werden soll und die Du im VBA-Code im Array aufführst, ein Leerzeichen anhängst. Sprich anstelle von

"ONE"

müsste dann dort

"ONE "

stehen. Habe das aber nicht getestet.

MfG,
Oliver
Da hier der einzige Lohn für die Helfer eine Rückmeldung ist, wäre es nett, wenn Du
ein Feedback abgeben könntest, ob der Lösungsvorschlag Dein Problem gelöst hat.

Antwort 2 von BenjaminM vom 29.10.2020, 13:07 Options

Jupp das funzt mit dem Leerzeichen!

Aber wie muss ich den Code ändern um die leztzen Zahlen umzudrehen?

Also aus FIVE TWENTY -> TWENTY FIVE zu machen???

Gruß Benjae

Antwort 3 von lorf55 vom 29.10.2020, 13:24 OptionsLösung

Lösung
Hallo,

In der Funktion Wort musst du das etwas umstellen:
statt
Wort = BisNINETEEN(h Mod 10) & IIf(h Mod 10 > 0, "AND ", "") & TEEN (Int(h / 10))

könnte ich mir
Wort = IIf(wert > 100, " AND ", "") & TEEN(Int(h / 10)) & BisNINETEEN(h Mod 10)

vorstellen.

Gruß
lorf

Antwort 4 von coros vom 29.10.2020, 13:33 Options

Hallo benjae,

tausche die Funktion „Private Function Wort(wert As Integer) As String“ gegen nachfolgenden aus.

Private Function Wort(wert As Integer) As String
Dim h As Integer
h = wert Mod 100
If h < 20 Then
Wort = BisNINETEEN(h)
Else
Wort = TEEN(Int(h / 10)) & IIf(h Mod 10 > 0, "AND ", "") & _
BisNINETEEN(h Mod 10)
End If
MsgBox Wort
h = (wert Mod 1000 - h) / 100
If h > 0 Then Wort = BisNINETEEN(h) & "HUNDRED " & Wort
End Function



Wenn das „And“ weg soll, nehme die Funktion

Private Function Wort(wert As Integer) As String
Dim h As Integer
h = wert Mod 100
If h < 20 Then
Wort = BisNINETEEN(h)
Else
Wort = TEEN(Int(h / 10)) & _
BisNINETEEN(h Mod 10)
End If
MsgBox Wort
h = (wert Mod 1000 - h) / 100
If h > 0 Then Wort = BisNINETEEN(h) & "HUNDRED " & Wort
End Function

MfG,
Oliver
Da hier der einzige Lohn für die Helfer eine Rückmeldung ist, wäre es nett, wenn Du
ein Feedback abgeben könntest, ob der Lösungsvorschlag Dein Problem gelöst hat.

Antwort 5 von BenjaminM vom 29.10.2020, 13:44 Options

Danke Lorf!!!

Manchmal sieht man den Wald vor lauter Bäumen nicht!

Gruß Benjae

Ähnliche Themen

Zahlen zuordnen
Sandra001.  15.06.2007 - 70 Hits - 7 Antworten

excel: gewisse wörter herausfiltern aus Spalte
Vicewein  04.07.2007 - 26 Hits - 2 Antworten

Zahlen zuordnen
Martina101  15.07.2007 - 9 Hits - 10 Antworten

Formatierung Zahlen
Rolando  02.08.2007 - 96 Hits - 1 Antwort

Wörter per Makro suchen und markieren
Probot  28.10.2008 - 8 Hits - 8 Antworten

Hinweis

Diese Frage ist schon etwas älter, Sie können daher nicht mehr auf sie antworten. Sollte Ihre Frage noch nicht gelöst sein, stellen Sie einfach eine neue Frage im Forum..

Neue Einträge

Version: supportware 1.9.150 / 10.06.2022, Startzeit:Mon Jan 26 01:23:17 2026