Re: EXCEL-format bunky

From: Kamil (sverak@csadbk.cz)
Date: 02. 10. 2003, 15:39 CEST


> chci se zeptat jestli se da nejak udelat v Excelu to kdyz zadam do bunky nejake
> cislo napr 22000 aby se mi bud v te bunce nebo nekde vedle napsala castka slovy
> dvacetdvatisickorun napr.

melo by to fungovat do milionu bez desetinych mist ... napsal sem
to pro nekoho uz davno a nevim esli to pouziva, tak to radeji
otestuj, ale snad to bude fungovat...


-----------------------------------------------------------
Option Explicit

Function CisloNaText(cislo)
    Dim text As String
    
        '________kontroly ________
    
    If cislo > 1000000 Then 
                MsgBox "cislo je vetsi jak Milion"
                Exit Function    'do milionu
    End If
    cislo = Int(cislo)      'Zaokrouhli cislo
        '_________________________
    
    If cislo >= 1000 And cislo < 5000 Then
        text = retezec(Int(cislo / 1000) * 1000)
        cislo = cislo - Int(cislo / 1000) * 1000
    ElseIf cislo >= 5000 Then
        text = TriCisla(Left(Trim(Str(cislo)), Len(Trim(Str(cislo))) - 3)) & "tisíc"
        cislo = cislo - Val(Left(Trim(Str(cislo)), Len(Trim(Str(cislo))) - 3)) * 1000
    End If
    text = text & TriCisla(cislo)
    CisloNaText = text
End Function

Private Function TriCisla(cislo)
    Dim text As String
            
            'Pro čísla od 100 do 999
    If cislo > 99 Then
        text = retezec(Int(cislo / 100) * 100)
        cislo = cislo - Int(cislo / 100) * 100
    End If
        'Pro čísla do 100
    If cislo > 19 Then
        text = text & retezec(Int(cislo / 10) * 10) & retezec(cislo - Int(cislo / 10) * 10)
    Else
        text = text & retezec(cislo)
    End If
    TriCisla = text
End Function

Private Function retezec(cislo)
    Dim text As String
    If cislo = 1 Then
            text = "jedna"
    ElseIf cislo = 2 Then
            text = "dvě"
    ElseIf cislo = 3 Then
            text = "tři"
    ElseIf cislo = 4 Then
            text = "čtyři"
    ElseIf cislo = 5 Then
            text = "pět"
    ElseIf cislo = 6 Then
            text = "±est"
    ElseIf cislo = 7 Then
            text = "sedm"
    ElseIf cislo = 8 Then
            text = "osm"
    ElseIf cislo = 9 Then
            text = "devět"
    ElseIf cislo = 10 Then
            text = "deset"
    ElseIf cislo = 11 Then
            text = "jedenáct"
    ElseIf cislo >= 12 And cislo <= 18 Then
            text = retezec(Val(Right(cislo, 1))) & "náct"
    ElseIf cislo = 19 Then
            text = "devatenáct"
    ElseIf cislo = 20 Then
            text = "dvacet"
    ElseIf cislo >= 30 And cislo <= 40 Then
            text = retezec(Val(Left(cislo, 1))) & "cet"
    ElseIf cislo = 50 Then
            text = "padesát"
    ElseIf cislo = 60 Then
            text = "±edesát"
    ElseIf cislo >= 70 And cislo <= 80 Then
            text = retezec(Val(Left(cislo, 1))) & "desát"
    ElseIf cislo = 90 Then
            text = "devadesát"
    ElseIf cislo = 100 Then
            text = "sto"
    ElseIf cislo >= 200 And cislo <= 400 Then
        text = retezec(Val(Left(cislo, 1))) & "sta"
    ElseIf cislo >= 500 And cislo <= 900 Then
        text = retezec(Val(Left(cislo, 1))) & "set"
    ElseIf cislo = 1000 Then
            text = "tisíc"
    ElseIf cislo = 2000 Then
            text = "dvatisíce"
    ElseIf cislo >= 3000 And cislo <= 4000 Then
        text = retezec(Val(Left(cislo, 1))) & "tisíce"
    End If
    
    retezec = text
End Function







-- 
cao,
 Kamil 



This archive was generated by hypermail 2.1.3 : 02. 10. 2003, 15:38 CEST