Advertisement
Guest User

Untitled

a guest
Aug 13th, 2019
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Sub UnderLineText(ByRef InText As Range)
  2.   InText.Formula = CStr(InText.Value)  ' converts result of formula into a string literal
  3.    'or: InText.offset(0,1).formula = cstr(InText.value) -- writes the value in the cell next to InText
  4.  InText.Characters(1, 5).Font.Underline = True
  5.   UnderLineText = InText
  6. End Sub
  7. Function SpellNumberToPortuguese(ByVal pNumber)
  8. 'Updateby20131113
  9. Dim Euros, Cents
  10. arr = Array("", "", " Mil ", " Milhões ", " Mil Milhões ", " Bilhões")
  11. pNumber = Trim(Str(pNumber))
  12. xDecimal = InStr(pNumber, ".")
  13. If xDecimal > 0 Then
  14.     Cents = GetTens(Left(Mid(pNumber, xDecimal + 1) & "00", 2))
  15.     pNumber = Trim(Left(pNumber, xDecimal - 1))
  16. End If
  17. xIndex = 1
  18. Do While pNumber <> ""
  19.     xHundred = ""
  20.     XValue = Right(pNumber, 3)
  21.     If Val(XValue) <> 0 Then
  22.         XValue = Right("000" & XValue, 3)
  23.         If Mid(XValue, 1, 1) <> "0" Then
  24.             xHundred = GetHundreds(Mid(XValue, 1))
  25.         ElseIf Mid(XValue, 2, 1) <> "0" Then
  26.             xHundred = GetTens(Mid(XValue, 2))
  27.         ElseIf Mid(XValue, 3, 1) <> "0" Then
  28.             xHundred = GetDigit(Mid(XValue, 3))
  29.         End If
  30.     End If
  31.     If xHundred <> "" Then
  32.         Euros = xHundred & arr(xIndex) & Euros
  33.     End If
  34.     If Len(pNumber) > 3 Then
  35.         pNumber = Left(pNumber, Len(pNumber) - 3)
  36.     Else
  37.         pNumber = ""
  38.     End If
  39.     xIndex = xIndex + 1
  40. Loop
  41. Select Case Euros
  42.     Case ""
  43.         Euros = "No Euros"
  44.     Case "One"
  45.         Euros = "One Euro"
  46.     Case Else
  47.         Euros = Euros & " Euros"
  48. End Select
  49. Select Case Cents
  50.     Case ""
  51.         Cents = " e Zero Cêntimos"
  52.     Case "One"
  53.         Cents = " e um Cêntimo"
  54.     Case Else
  55.         Cents = " e " & Cents & " Cêntimos"
  56. End Select
  57. SpellNumberToPortuguese = Euros & Cents
  58. End Function
  59. Function GetHundreds(pNumber)
  60. Dim Result As String
  61. Dim pHundreds As String
  62. pHundreds = Mid(pNumber, 1, 1)
  63. Result = ""
  64.  
  65. If pHundreds = "-" Then
  66.     Result = "Menos "
  67.     If Mid(pNumber, 2, 1) <> "0" Then
  68.         Result = Result & GetTens(Mid(pNumber, 2))
  69.     ElseIf Right(pNumber, 1) <> "0" Then
  70.         Result = Result & GetDigit(Right(pNumber, 1))
  71.     End If
  72.     GetHundreds = Result
  73.     Exit Function
  74. End If
  75.  
  76. If pHundreds = "1" And (Mid(pNumber, 2, 1) <> "0" Or Mid(pNumber, 3, 1) <> "0") Then
  77.     Result = "Cento"
  78. Else
  79.     Select Case Val(pHundreds)
  80.         Case 1: Result = "Cem"
  81.         Case 2: Result = "Duzentos"
  82.         Case 3: Result = "Trezentos"
  83.         Case 4: Result = "Quatrocentos"
  84.         Case 5: Result = "Quinhentos"
  85.         Case 6: Result = "Seiscentos"
  86.         Case 7: Result = "Setecentos"
  87.         Case 8: Result = "Oitocentos"
  88.         Case 9: Result = "Novecentos"
  89.         Case Else: Result = ""
  90.     End Select
  91. End If
  92. If Mid(pNumber, 2, 1) <> "0" Then
  93.     Result = Result & " e " & GetTens(Mid(pNumber, 2))
  94. ElseIf Right(pTens, 1) <> "0" Then
  95.     Result = Result & " e " & GetDigit(Right(pNumber, 1))
  96. End If
  97. GetHundreds = Result
  98. End Function
  99. Function GetTens(pTens)
  100. Dim Result As String
  101. Result = ""
  102.  
  103. If pHundreds = "-" Then
  104.     Result = "Menos"
  105.     Exit Function
  106. End If
  107.  
  108. If Val(Left(pTens, 1)) = 1 Then
  109.     Select Case Val(pTens)
  110.         Case 10: Result = "Dez"
  111.         Case 11: Result = "Onze"
  112.         Case 12: Result = "Doze"
  113.         Case 13: Result = "Treze"
  114.         Case 14: Result = "Catorze"
  115.         Case 15: Result = "Quinze"
  116.         Case 16: Result = "Desasseis"
  117.         Case 17: Result = "Dezassete"
  118.         Case 18: Result = "Dezoito"
  119.         Case 19: Result = "Dezanove"
  120.         Case Else
  121.     End Select
  122. Else
  123. Select Case Val(Left(pTens, 1))
  124.     Case 2: Result = "Vinte"
  125.     Case 3: Result = "Trinta"
  126.     Case 4: Result = "Quarenta"
  127.     Case 5: Result = "Cinquenta"
  128.     Case 6: Result = "Sessenta"
  129.     Case 7: Result = "Setenta"
  130.     Case 8: Result = "Oitenta"
  131.     Case 9: Result = "Noventa"
  132.     Case Else
  133. End Select
  134. If Val(Right(pTens, 1)) > 0 Then
  135. Result = Result & " e " & GetDigit(Right(pTens, 1))
  136. End If
  137. End If
  138. GetTens = Result
  139. End Function
  140. Function GetDigit(pDigit)
  141.  
  142. If pHundreds = "-" Then
  143.     Result = "Menos"
  144.     Exit Function
  145. End If
  146.  
  147. Select Case Val(pDigit)
  148.     Case 1: GetDigit = "Um"
  149.     Case 2: GetDigit = "Dois"
  150.     Case 3: GetDigit = "Três"
  151.     Case 4: GetDigit = "Quatro"
  152.     Case 5: GetDigit = "Cinco"
  153.     Case 6: GetDigit = "Seis"
  154.     Case 7: GetDigit = "Sete"
  155.     Case 8: GetDigit = "Oito"
  156.     Case 9: GetDigit = "Nove"
  157.     Case Else: GetDigit = ""
  158. End Select
  159. End Function
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement