Advertisement
cahb52

FUNCION CONVERTIR NUMEROS A LETRAS EXCEL PARA CUADROS MED GT

Oct 2nd, 2017
187
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Function Num_texto(Numero)
  2. Dim Texto
  3. Dim Millones
  4. Dim Miles
  5. Dim Cientos
  6. Dim Decimales
  7. Dim Cadena
  8. Dim CadMillones
  9. Dim CadMiles
  10. Dim CadCientos
  11. Texto = Numero
  12. Texto = FormatNumber(Texto, 2)
  13. Texto = Right(Space(14) & Texto, 14)
  14. Millones = Mid(Texto, 1, 3)
  15. Miles = Mid(Texto, 5, 3)
  16. Cientos = Mid(Texto, 9, 3)
  17. Decimales = Mid(Texto, 13, 2)
  18. CadMillones = ConvierteCifra(Millones, 1)
  19. CadMiles = ConvierteCifra(Miles, 1)
  20. CadCientos = ConvierteCifra(Cientos, 0)
  21. If Trim(CadMillones) > "" Then
  22. If Trim(CadMillones) = "UN" Then
  23. Cadena = CadMillones & " MILLON"
  24. Else
  25. Cadena = CadMillones & " MILLONES"
  26. End If
  27. End If
  28. If Trim(CadMiles) > "" Then
  29. Cadena = Cadena & " " & CadMiles & " MIL"
  30. End If
  31. If Trim(CadMiles & CadCientos) = "UN" Then
  32. Cadena = Cadena & "UNO"
  33. Else
  34. If Miles & Cientos = "000000" Then
  35. Cadena = Cadena & " " & Trim(CadCientos) & ""
  36. Else
  37. Cadena = Cadena & " " & Trim(CadCientos) & ""
  38. End If
  39. End If
  40. Num_texto = Trim(Cadena)
  41. End Function
  42.  
  43. Function ConvierteCifra(Texto, SW)
  44. Dim Centena
  45. Dim Decena
  46. Dim Unidad
  47. Dim txtCentena
  48. Dim txtDecena
  49. Dim txtUnidad
  50. Centena = Mid(Texto, 1, 1)
  51. Decena = Mid(Texto, 2, 1)
  52. Unidad = Mid(Texto, 3, 1)
  53. Select Case Centena
  54. Case "1"
  55. txtCentena = "CIEN"
  56. If Decena & Unidad <> "00" Then
  57. txtCentena = "CIENTO"
  58. End If
  59. Case "2"
  60. txtCentena = "DOSCIENTOS"
  61. Case "3"
  62. txtCentena = "TRESCIENTOS"
  63. Case "4"
  64. txtCentena = "CUATROCIENTOS"
  65. Case "5"
  66. txtCentena = "QUINIENTOS"
  67. Case "6"
  68. txtCentena = "SEISCIENTOS"
  69. Case "7"
  70. txtCentena = "SETECIENTOS"
  71. Case "8"
  72. txtCentena = "OCHOCIENTOS"
  73. Case "9"
  74. txtCentena = "NOVECIENTOS"
  75. End Select
  76.  
  77. Select Case Decena
  78. Case "1"
  79. txtDecena = "DIEZ"
  80. Select Case Unidad
  81. Case "1"
  82. txtDecena = "ONCE"
  83. Case "2"
  84. txtDecena = "DOCE"
  85. Case "3"
  86. txtDecena = "TRECE"
  87. Case "4"
  88. txtDecena = "CATORCE"
  89. Case "5"
  90. txtDecena = "QUINCE"
  91. Case "6"
  92. txtDecena = "DIECISEIS"
  93. Case "7"
  94. txtDecena = "DIECISIETE"
  95. Case "8"
  96. txtDecena = "DIECIOCHO"
  97. Case "9"
  98. txtDecena = "DIECINUEVE"
  99. End Select
  100. Case "2"
  101. txtDecena = "VEINTE"
  102. If Unidad <> "0" Then
  103. txtDecena = "VEINTI"
  104. End If
  105. Case "3"
  106. txtDecena = "TREINTA"
  107. If Unidad <> "0" Then
  108. txtDecena = "TREINTA Y "
  109. End If
  110. Case "4"
  111. txtDecena = "CUARENTA"
  112. If Unidad <> "0" Then
  113. txtDecena = "CUARENTA Y "
  114. End If
  115. Case "5"
  116. txtDecena = "CINCUENTA"
  117. If Unidad <> "0" Then
  118. txtDecena = "CINCUENTA Y "
  119. End If
  120. Case "6"
  121. txtDecena = "SESENTA"
  122. If Unidad <> "0" Then
  123. txtDecena = "SESENTA Y "
  124. End If
  125. Case "7"
  126. txtDecena = "SETENTA"
  127. If Unidad <> "0" Then
  128. txtDecena = "SETENTA Y "
  129. End If
  130. Case "8"
  131. txtDecena = "OCHENTA"
  132. If Unidad <> "0" Then
  133. txtDecena = "OCHENTA Y "
  134. End If
  135. Case "9"
  136. txtDecena = "NOVENTA"
  137. If Unidad <> "0" Then
  138. txtDecena = "NOVENTA Y "
  139. End If
  140. End Select
  141.  
  142. If Decena <> "1" Then
  143. Select Case Unidad
  144. Case "1"
  145. If SW Then
  146. txtUnidad = "UN"
  147. Else
  148. txtUnidad = "UNO"
  149. End If
  150. Case "2"
  151. txtUnidad = "DOS"
  152. Case "3"
  153. txtUnidad = "TRES"
  154. Case "4"
  155. txtUnidad = "CUATRO"
  156. Case "5"
  157. txtUnidad = "CINCO"
  158. Case "6"
  159. txtUnidad = "SEIS"
  160. Case "7"
  161. txtUnidad = "SIETE"
  162. Case "8"
  163. txtUnidad = "OCHO"
  164. Case "9"
  165. txtUnidad = "NUEVE"
  166. End Select
  167. End If
  168. ConvierteCifra = txtCentena & " " & txtDecena & txtUnidad
  169. End Function
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement