Option Explicit ' Вставьте весь код в обычный модуль VBA настольного Excel. ' Формула в ячейке: =RUBWORDS(A2) ' Сумма должна быть числом от 0 до 999999999999,99 и уже округлена до копеек. Public Function RUBWORDS(ByVal amount As Variant) As Variant On Error GoTo BadValue If IsError(amount) Then GoTo BadValue If IsEmpty(amount) Then RUBWORDS = "" Exit Function End If If VarType(amount) = vbString Then If Len(Trim$(amount)) = 0 Then RUBWORDS = "" Exit Function End If GoTo BadValue End If If VarType(amount) = vbBoolean Or Not IsNumeric(amount) Then GoTo BadValue Dim value As Double value = CDbl(amount) If value < 0# Or value > 999999999999.99 Then GoTo BadValue Dim scaled As Double Dim totalKopecks As Double scaled = value * 100# totalKopecks = Fix(scaled + 0.5) If Abs(scaled - totalKopecks) > 0.000001 Then GoTo BadValue Dim rubles As Double Dim kopecks As Integer rubles = Fix(totalKopecks / 100#) kopecks = CInt(totalKopecks - rubles * 100#) Dim result As String Dim scaleIndex As Integer Dim group As Integer Dim groupWords As String For scaleIndex = 3 To 0 Step -1 group = CInt(Fix(rubles / (1000# ^ scaleIndex)) - _ 1000# * Fix(rubles / (1000# ^ (scaleIndex + 1)))) If group > 0 Then groupWords = TriadWords(group, scaleIndex = 1) AppendWord result, groupWords Select Case scaleIndex Case 1 AppendWord result, FormOf(group, "тысяча", "тысячи", "тысяч") Case 2 AppendWord result, FormOf(group, "миллион", "миллиона", "миллионов") Case 3 AppendWord result, FormOf(group, "миллиард", "миллиарда", "миллиардов") End Select End If Next scaleIndex If rubles = 0# Then AppendWord result, "ноль" AppendWord result, FormOf(rubles, "рубль", "рубля", "рублей") AppendWord result, Format$(kopecks, "00") AppendWord result, FormOf(kopecks, "копейка", "копейки", "копеек") RUBWORDS = UCase$(Left$(result, 1)) & Mid$(result, 2) Exit Function BadValue: RUBWORDS = CVErr(xlErrValue) End Function Private Function TriadWords(ByVal number As Integer, ByVal female As Boolean) As String Dim unitsMale As Variant Dim unitsFemale As Variant Dim teens As Variant Dim tens As Variant Dim hundreds As Variant unitsMale = Array("", "один", "два", "три", "четыре", "пять", "шесть", "семь", "восемь", "девять") unitsFemale = Array("", "одна", "две", "три", "четыре", "пять", "шесть", "семь", "восемь", "девять") teens = Array("десять", "одиннадцать", "двенадцать", "тринадцать", "четырнадцать", _ "пятнадцать", "шестнадцать", "семнадцать", "восемнадцать", "девятнадцать") tens = Array("", "", "двадцать", "тридцать", "сорок", "пятьдесят", _ "шестьдесят", "семьдесят", "восемьдесят", "девяносто") hundreds = Array("", "сто", "двести", "триста", "четыреста", "пятьсот", _ "шестьсот", "семьсот", "восемьсот", "девятьсот") Dim remainder As Integer Dim digit As Integer Dim result As String digit = number \ 100 If digit > 0 Then AppendWord result, CStr(hundreds(digit)) remainder = number Mod 100 If remainder >= 10 And remainder <= 19 Then AppendWord result, CStr(teens(remainder - 10)) Else digit = remainder \ 10 If digit > 0 Then AppendWord result, CStr(tens(digit)) digit = remainder Mod 10 If digit > 0 Then If female Then AppendWord result, CStr(unitsFemale(digit)) Else AppendWord result, CStr(unitsMale(digit)) End If End If End If TriadWords = result End Function Private Function FormOf(ByVal number As Double, ByVal one As String, _ ByVal twoToFour As String, ByVal many As String) As String Dim lastTwo As Integer Dim lastDigit As Integer lastTwo = CInt(number - 100# * Fix(number / 100#)) lastDigit = CInt(number - 10# * Fix(number / 10#)) If lastTwo >= 11 And lastTwo <= 14 Then FormOf = many ElseIf lastDigit = 1 Then FormOf = one ElseIf lastDigit >= 2 And lastDigit <= 4 Then FormOf = twoToFour Else FormOf = many End If End Function Private Sub AppendWord(ByRef result As String, ByVal word As String) If Len(word) = 0 Then Exit Sub If Len(result) > 0 Then result = result & " " result = result & word End Sub