Advertisement
cahb

Numeros a letras Excel

Apr 21st, 2023
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VisualBasic 2.81 KB | Software | 0 0
  1. Function CONVERTIRNUMEROLETRA(tyCantidad As Currency) As String
  2.  
  3.     Dim lyCantidad As Currency, lyCentavos As Currency, lnDigito As Byte, lnPrimerDigito As Byte, lnSegundoDigito As Byte, lnTercerDigito As Byte, lcBloque As String, lnNumeroBloques As Byte, lnBloqueCero
  4.    
  5.     Dim laUnidades As Variant, laDecenas As Variant, laCentenas As Variant, I As Variant
  6.    
  7.     tyCantidad = Round(tyCantidad, 2)
  8.    
  9.     lyCantidad = Int(tyCantidad)
  10.    
  11.     lyCentavos = (tyCantidad - lyCantidad) * 100
  12.    
  13.     laUnidades = Array("UNO", "DOS", "TRES", "CUATRO", "CINCO", "SEIS", "SIETE", "OCHO", "NUEVE", "DIEZ", "ONCE", "DOCE", "TRECE", "CATORCE", "QUINCE", "DIECISEIS", "DIECISIETE", "DIECIOCHO", "DIECINUEVE", "VEINTE", "VEINTIUN", "VEINTIDOS", "VEINTITRES", "VEINTICUATRO", "VEINTICINCO", "VEINTISEIS", "VEINTISIETE", "VEINTIOCHO", "VEINTINUEVE")
  14.    
  15.     laDecenas = Array("DIEZ", "VEINTE", "TREINTA", "CUARENTA", "CINCUENTA", "SESENTA", "SETENTA", "OCHENTA", "NOVENTA")
  16.    
  17.     laCentenas = Array("CIENTO", "DOSCIENTOS", "TRESCIENTOS", "CUATROCIENTOS", "QUINIENTOS", "SEISCIENTOS", "SETECIENTOS", "OCHOCIENTOS", "NOVECIENTOS")
  18.    
  19.     lnNumeroBloques = 1
  20.    
  21.     Do
  22.    
  23.     lnPrimerDigito = 0
  24.    
  25.     lnSegundoDigito = 0
  26.    
  27.     lnTercerDigito = 0
  28.    
  29.     lcBloque = ""
  30.    
  31.     lnBloqueCero = 0
  32.    
  33.     For I = 1 To 3
  34.    
  35.     lnDigito = lyCantidad Mod 10
  36.    
  37.     If lnDigito <> 0 Then
  38.    
  39.     Select Case I
  40.    
  41.     Case 1
  42.    
  43.     lcBloque = " " & laUnidades(lnDigito - 1)
  44.    
  45.     lnPrimerDigito = lnDigito
  46.    
  47.     Case 2
  48.    
  49.     If lnDigito <= 2 Then
  50.    
  51.     lcBloque = " " & laUnidades((lnDigito * 10) + lnPrimerDigito - 1)
  52.    
  53.     Else
  54.    
  55.     lcBloque = " " & laDecenas(lnDigito - 1) & IIf(lnPrimerDigito <> 0, " Y", Null) & lcBloque
  56.    
  57.     End If
  58.    
  59.     lnSegundoDigito = lnDigito
  60.    
  61.     Case 3
  62.    
  63.     lcBloque = " " & IIf(lnDigito = 1 And lnPrimerDigito = 0 And lnSegundoDigito = 0, "CIEN", laCentenas(lnDigito - 1)) & lcBloque
  64.    
  65.     lnTercerDigito = lnDigito
  66.    
  67.     End Select
  68.    
  69.     Else
  70.    
  71.     lnBloqueCero = lnBloqueCero + 1
  72.    
  73.     End If
  74.    
  75.     lyCantidad = Int(lyCantidad / 10)
  76.    
  77.     If lyCantidad = 0 Then
  78.    
  79.     Exit For
  80.    
  81.     End If
  82.    
  83.     Next I
  84.    
  85.     Select Case lnNumeroBloques
  86.    
  87.     Case 1
  88.    
  89.     CONVERTIRNUMEROLETRA = lcBloque
  90.    
  91.     Case 2
  92.    
  93.     CONVERTIRNUMEROLETRA = lcBloque & IIf(lnBloqueCero = 3, Null, "MIL") & CONVERTIRNUMEROLETRA
  94.    
  95.     Case 3
  96.    
  97.     CONVERTIRNUMEROLETRA = lcBloque & IIf(lnPrimerDigito = 1 And lnSegundoDigito = 0 And lnTercerDigito = 0, " MILLON", " MILLONES") & CONVERTIRNUMEROLETRA
  98.    
  99.     End Select
  100.    
  101.     lnNumeroBloques = lnNumeroBloques + 1
  102.    
  103.     Loop Until lyCantidad = 0
  104.    
  105.     CONVERTIRNUMEROLETRA = CONVERTIRNUMEROLETRA
  106.  
  107. End Function
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement