Excel: convertir números a texto

Que tal estimado experto tengo una hoja de excel con 7500 registros, con una columna que maneja diferentes formatos (texto y numéricos)en las celdas que componen esa columna, y cuando quiero convertir todo a texto, me pasa esto en las celdas que tienen formato numérico:
Antes de convertir
22800100000114
Después de convertir
2.28001E+13
De antemano gracias
Armin Canto

1 respuesta

1
Respuesta de
Hola
Pega este código en un modulo del libro en el que deseas cambiar los números a letras, esto creara una fórmula llamada letra
Ejemplo.
=letra(a1)
Código...
Function pesos(Rcantidad As Double) As String
Dim Rcant As String
Dim cAux As String
Dim Runi As String
Dim Rdec As String
Dim rdecs As String
Dim rcen As String
Dim riter As Integer
Dim rnum As String
Dim cDecim As String
'Runi$ , Rdec$, Rdecs$, Rcen$, Rnum$, Riter$
Rcant = ""
Runi = " UN DOS TRES CUATROCINCO SEIS SIETE OCHO NUEVE "
Rdec = "DIEZ ONCE DOCE TRECE CATORCE QUINCE DIECISEIS DIECISIETEDIECIOCHO DIECINUEVE"
rdecs = " VEINTE TREINTA CUARENTA CINCUENTASESENTA SETENTA OCHENTA NOVENTA "
rcen = " DOS TRES CUATRO SEIS SETE OCHO NOVE "
Rcant = Trim(Str(Rcantidad))
If InStr(1, Rcant, ".") > 0 Then
'cAux = Left(Rcant, InStr(1, Rcant, ".") + 2)
cAux = cRound(Rcant, 2)
Rcant = cAux
If Mid(Rcant, Len(Rcant) - 1, 1) = "." Then
Rcant = Rcant + "0"
Rcant = Space(12 - Len(Left(Rcant, Len(Rcant) - 3))) + Rcant
Else
Rcant = Space(12 - Len(Left(Rcant, Len(Rcant) - 3))) + Rcant
cDecim = Right(Rcant, 2)
End If
Else
cDecim = "00"
End If
rnum = Mid(Rcant, 1, 12)
Rcant = ""
If Len(rnum) < 12 Then
rnum = Space(12 - Len(rnum)) + rnum
End If
If Val(rnum) = 0 Then
Rcant = &quot;CERO PESOS &quot;
Else
riter = 1
While riter < 13
If Mid(rnum, riter, 1) <> &quot; &quot; And Mid(rnum, riter, 1) <> &quot;0&quot; Then
Select Case Mid(rnum, riter, 1)
Case &quot;1&quot;
If Mid(rnum, riter + 1, 2) = &quot;00&quot; Then
Rcant = Rcant + &quot;CIEN &quot;
Else
Rcant = Rcant + &quot;CIENTO &quot;
End If
Case &quot;5&quot;
Rcant = Rcant + &quot;QUINIENTOS &quot;
Case Else
Rcant = Rcant + RTrim(Mid(rcen, Val(Mid(rnum, riter, 1)) * 6 + 1, 6)) + &quot;CIENTOS &quot;
End Select
End If
If Mid(rnum, riter + 1, 1) <> &quot; &quot; And Mid(rnum, riter + 1, 1) <> &quot;0&quot; Then
Select Case Mid(rnum, riter + 1, 1)
Case &quot;1&quot;
Rcant = Rcant + RTrim(Mid(Rdec, Val(Mid(rnum, riter + 2, 1)) * 10 + 1, 10)) + &quot; &quot;
Case &quot;2&quot;
If Mid(rnum, riter + 2, 1) = &quot;0&quot; Then
Rcant = Rcant + &quot;VEINTE &quot;
Else
Rcant = Rcant + &quot;VEINTI&quot; + RTrim(Mid(Runi, Val(Mid(rnum, riter + 2, 1)) * 6 + 1, 6)) + &quot; &quot;
End If
Case Else
Rcant = Rcant + RTrim(Mid(rdecs, Val(Mid(rnum, riter + 1, 1)) * 9 + 1, 9))
If Mid(rnum, riter + 2, 1) > &quot;0&quot; Then
Rcant = Rcant + &quot; Y &quot; + RTrim(Mid(Runi, Val(Mid(rnum, riter + 2, 1)) * 6 + 1, 6)) + &quot; &quot;
Else
Rcant = Rcant + &quot; &quot;
End If
End Select
End If
If Mid(rnum, riter + 2, 1) <> &quot; &quot; And Mid(rnum, riter + 1, 1) < &quot;1&quot; And Mid(rnum, riter + 1, 2) <> &quot;00&quot; Then
Rcant = Rcant + RTrim(Mid(Runi, Val(Mid(rnum, riter + 2, 1)) * 6 + 1, 6)) + &quot; &quot;
End If
Select Case riter
Case 1
If Mid(rnum, 1, 3) <> Space(3) And Mid(rnum, 1, 3) <> &quot;000&quot; Then
Rcant = Rcant + &quot;MIL &quot;
End If
Case 4
If Mid(rnum, 1, 6) <> Space(6) And Mid(rnum, 1, 6) <> &quot;000000&quot; Then
If Mid(rnum, 1, 6) <> Space(5) + &quot;1&quot; Then
Rcant = Rcant + &quot;MILLONES &quot;
Else
Rcant = Rcant + &quot;MILLON &quot;
End If
End If
Case 7
If Mid(rnum, 1, 9) <> Space(9) And Mid(rnum, 7, 3) <> &quot;000&quot; Then
Rcant = Rcant + &quot;MIL &quot;
End If
End Select
riter = riter + 3
Wend
If rnum = Space(11) + &quot;1&quot; Then
Rcant = Rcant + &quot;PESO &quot;
Else
If Mid(rnum, 7, 6) = &quot;000000&quot; Then
Rcant = Rcant + &quot;DE PESOS &quot;
Else
Rcant = Rcant + &quot;PESOS &quot;
End If
End If
End If
Rcant = LTrim(RTrim((Rcant + cDecim + &quot;/100 M. N.&quot;)))
pesos = Rcant
End Function
Function cRound(ByVal cVal, ByVal nDec) As String
Dim cAux, cRet As String
Dim nI, nPos, nAcum, nCurVal, nNextVal As Integer
nAcum = 0
nCurVal = 0
nNextVal = 0
cRet = &quot;&quot;
nPos = InStr(1, cVal, &quot;.&quot;)
If nPos = 0 Then
&#39;cAux = Padc(&quot;&quot;, nDec, &quot;0&quot;)
cRet = cVal + &quot;.&quot; + &quot;00&quot;
Else
cAux = Right(cVal, Len(cVal) - nPos)
If Len(cAux) > nDec Then
nPos = Len(cAux) - 1
For nI = nPos To nDec Step -1
nCurVal = Int(Val(Mid(cAux, nI + 1, 1)))
nNextVal = Int(Val(Mid(cAux, nI, 1)))
If nCurVal < 5 Then
nAcum = nNextVal
Else
nAcum = nNextVal + 1
End If
cRet = Mid(cAux, 1, nI - 1) + Trim(Str(nAcum))
Next
nPos = InStr(1, cVal, &quot;.&quot;)
cRet = Left(cVal, nPos) + cRet
Else
nAcum = nDec - Len(Right(cVal, Len(cVal) - nPos))
cRet = cVal
For nI = 1 To nAcum
cRet = cRet + &quot;0&quot;
Next
End If
End If
cRound = cRet
End Function
Function letra(Numero)
Dim Texto
Dim Millones
Dim Miles
Dim Cientos
Dim Decimales
Dim Cadena
Dim CadMillones
Dim CadMiles
Dim CadCientos
Dim caddecimales
Texto = Round(Numero, 2)
Texto = FormatNumber(Texto, 2)
Texto = Right(Space(14) & Texto, 14)
Millones = Mid(Texto, 1, 3)
Miles = Mid(Texto, 5, 3)
Cientos = Mid(Texto, 9, 3)
Decimales = Mid(Texto, 13, 2)
CadMillones = ConvierteCifra(Millones, False)
CadMiles = ConvierteCifra(Miles, False)
CadCientos = ConvierteCifra(Cientos, True)
caddecimales = ConvierteDecimal(Decimales)
If Trim(CadMillones) > &quot;&quot; Then
If Trim(CadMillones) = &quot;UN&quot; Then
Cadena = CadMillones & &quot; MILLON&quot;
Else
Cadena = CadMillones & &quot; MILLONES&quot;
End If
End If
If Trim(CadMiles) > &quot;&quot; Then
If Trim(CadMiles) = &quot;UN&quot; Then
CadMiles = &quot;&quot;
Cadena = Cadena & &quot;&quot; & CadMiles & &quot;MIL&quot;
CadMiles = &quot;UN&quot;
Else
Cadena = Cadena & &quot; &quot; & CadMiles & &quot; MIL&quot;
End If
End If
If Trim(CadMiles) > &quot;001&quot; Then
CadMiles = &quot;MIL&quot;
End If
If Decimales = &quot;00&quot; Then
If Trim(CadMillones & CadMiles & CadCientos & caddecimales) = &quot;UN&quot; Then
Cadena = Cadena & &quot;UNO &quot;
Else
If Miles & Cientos = &quot;000000&quot; Then
Cadena = Cadena & &quot; &quot; & Trim(CadCientos)
Else
Cadena = Cadena & &quot; &quot; & Trim(CadCientos)
End If
letra = Trim(Cadena)
End If
Else
If Trim(CadMillones & CadMiles & CadCientos & caddecimales) = &quot;UN&quot; Then
Cadena = Cadena & &quot;UNO &quot; & &quot;CON &quot; & Trim(caddecimales)
Else
If Millones & Miles & Cientos & Decimales = &quot;000000&quot; Then
Cadena = Cadena & &quot; &quot; & Trim(CadCientos)
Else
Cadena = Cadena & &quot; &quot; & Trim(CadCientos)
End If
letra = Trim(Cadena)
End If
End If
End Function
Function ConvierteCifra(Texto, IsCientos As Boolean)
Dim Centena
Dim Decena
Dim Unidad
Dim txtCentena
Dim txtDecena
Dim txtUnidad
Centena = Mid(Texto, 1, 1)
Decena = Mid(Texto, 2, 1)
Unidad = Mid(Texto, 3, 1)
Select Case Centena
Case &quot;1&quot;
txtCentena = &quot;CIEN&quot;
If Decena & Unidad <> &quot;00&quot; Then
txtCentena = &quot;CIENTO&quot;
End If
Case &quot;2&quot;
txtCentena = &quot;DOSCIENTOS&quot;
Case &quot;3&quot;
txtCentena = &quot;TRESCIENTOS&quot;
Case &quot;4&quot;
txtCentena = &quot;CUATROCIENTOS&quot;
Case &quot;5&quot;
txtCentena = &quot;QUINIENTOS&quot;
Case &quot;6&quot;
txtCentena = &quot;SEISCIENTOS&quot;
Case &quot;7&quot;
txtCentena = &quot;SETECIENTOS&quot;
Case &quot;8&quot;
txtCentena = &quot;OCHOCIENTOS&quot;
Case &quot;9&quot;
txtCentena = &quot;NOVECIENTOS&quot;
End Select
Select Case Decena
Case &quot;1&quot;
txtDecena = &quot;DIEZ&quot;
Select Case Unidad
Case &quot;1&quot;
txtDecena = &quot;ONCE&quot;
Case &quot;2&quot;
txtDecena = &quot;DOCE&quot;
Case &quot;3&quot;
txtDecena = &quot;TRECE&quot;
Case &quot;4&quot;
txtDecena = &quot;CATORCE&quot;
Case &quot;5&quot;
txtDecena = &quot;QUINCE&quot;
Case &quot;6&quot;
txtDecena = &quot;DIECISEIS&quot;
Case &quot;7&quot;
txtDecena = &quot;DIECISIETE&quot;
Case &quot;8&quot;
txtDecena = &quot;DIECIOCHO&quot;
Case &quot;9&quot;
txtDecena = &quot;DIECINUEVE&quot;
End Select
Case &quot;2&quot;
txtDecena = &quot;VEINTE&quot;
If Unidad <> &quot;0&quot; Then
txtDecena = &quot;VEINTI&quot;
End If
Case &quot;3&quot;
txtDecena = &quot;TREINTA&quot;
If Unidad <> &quot;0&quot; Then
txtDecena = &quot;TREINTA Y &quot;
End If
Case &quot;4&quot;
txtDecena = &quot;CUARENTA&quot;
If Unidad <> &quot;0&quot; Then
txtDecena = &quot;CUARENTA Y &quot;
End If
Case &quot;5&quot;
txtDecena = &quot;CINCUENTA&quot;
If Unidad <> &quot;0&quot; Then
txtDecena = &quot;CINCUENTA Y &quot;
End If
Case &quot;6&quot;
txtDecena = &quot;SESENTA&quot;
If Unidad <> &quot;0&quot; Then
txtDecena = &quot;SESENTA Y &quot;
End If
Case &quot;7&quot;
txtDecena = &quot;SETENTA&quot;
If Unidad <> &quot;0&quot; Then
txtDecena = &quot;SETENTA Y &quot;
End If
Case &quot;8&quot;
txtDecena = &quot;OCHENTA&quot;
If Unidad <> &quot;0&quot; Then
txtDecena = &quot;OCHENTA Y &quot;
End If
Case &quot;9&quot;
txtDecena = &quot;NOVENTA&quot;
If Unidad <> &quot;0&quot; Then
txtDecena = &quot;NOVENTA Y &quot;
End If
End Select
If Decena <> &quot;1&quot; Then
Select Case Unidad
Case &quot;1&quot;
If IsCientos = False Then
txtUnidad = &quot;UN&quot;
Else
txtUnidad = &quot;UNO&quot;
End If
Case &quot;2&quot;
txtUnidad = &quot;DOS&quot;
Case &quot;3&quot;
txtUnidad = &quot;TRES&quot;
Case &quot;4&quot;
txtUnidad = &quot;CUATRO&quot;
Case &quot;5&quot;
txtUnidad = &quot;CINCO&quot;
Case &quot;6&quot;
txtUnidad = &quot;SEIS&quot;
Case &quot;7&quot;
txtUnidad = &quot;SIETE&quot;
Case &quot;8&quot;
txtUnidad = &quot;OCHO&quot;
Case &quot;9&quot;
txtUnidad = &quot;NUEVE&quot;
End Select
End If
ConvierteCifra = txtCentena & &quot; &quot; & txtDecena & txtUnidad
End Function
Function ConvierteDecimal(Texto)
Dim Decenadecimal
Dim Unidaddecimal
Dim txtDecenadecimal
Dim txtUnidaddecimal
Decenadecimal = Mid(Texto, 1, 1)
Unidaddecimal = Mid(Texto, 2, 1)
Select Case Decenadecimal
Case &quot;1&quot;
txtDecenadecimal = &quot;DIEZ&quot;
Select Case Unidaddecimal
Case &quot;1&quot;
txtDecenadecimal = &quot;ONCE&quot;
Case &quot;2&quot;
txtDecenadecimal = &quot;DOCE&quot;
Case &quot;3&quot;
txtDecenadecimal = &quot;TRECE&quot;
Case &quot;4&quot;
txtDecenadecimal = &quot;CATORCE&quot;
Case &quot;5&quot;
txtDecenadecimal = &quot;QUINCE&quot;
Case &quot;6&quot;
txtDecenadecimal = &quot;DIECISEIS&quot;
Case &quot;7&quot;
txtDecenadecimal = &quot;DIECISIETE&quot;
Case &quot;8&quot;
txtDecenadecimal = &quot;DIECIOCHO&quot;
Case &quot;9&quot;
txtDecenadecimal = &quot;DIECINUEVE&quot;
End Select
Case &quot;2&quot;
txtDecenadecimal = &quot;VEINTE&quot;
If Unidaddecimal <> &quot;0&quot; Then
txtDecenadecimal = &quot;VEINTI&quot;
End If
Case &quot;3&quot;
txtDecenadecimal = &quot;TREINTA&quot;
If Unidaddecimal <> &quot;0&quot; Then
txtDecenadecimal = &quot;TREINTA Y &quot;
End If
Case &quot;4&quot;
txtDecenadecimal = &quot;CUARENTA&quot;
If Unidaddecimal <> &quot;0&quot; Then
txtDecenadecimal = &quot;CUARENTA Y &quot;
End If
Case &quot;5&quot;
txtDecenadecimal = &quot;CINCUENTA&quot;
If Unidaddecimal <> &quot;0&quot; Then
txtDecenadecimal = &quot;CINCUENTA Y &quot;
End If
Case &quot;6&quot;
txtDecenadecimal = &quot;SESENTA&quot;
If Unidaddecimal <> &quot;0&quot; Then
txtDecenadecimal = &quot;SESENTA Y &quot;
End If
Case &quot;7&quot;
txtDecenadecimal = &quot;SETENTA&quot;
If Unidaddecimal <> &quot;0&quot; Then
txtDecenadecimal = &quot;SETENTA Y &quot;
End If
Case &quot;8&quot;
txtDecenadecimal = &quot;OCHENTA&quot;
If Unidaddecimal <> &quot;0&quot; Then
txtDecenadecimal = &quot;OCHENTA Y &quot;
End If
Case &quot;9&quot;
txtDecenadecimal = &quot;NOVENTA&quot;
If Unidaddecimal <> &quot;0&quot; Then
txtDecenadecimal = &quot;NOVENTA Y &quot;
End If
End Select
If Decenadecimal <> &quot;1&quot; Then
Select Case Unidaddecimal
Case &quot;1&quot;
txtUnidaddecimal = &quot;UNO&quot;
Case &quot;2&quot;
txtUnidaddecimal = &quot;DOS&quot;
Case &quot;3&quot;
txtUnidaddecimal = &quot;TRES&quot;
Case &quot;4&quot;
txtUnidaddecimal = &quot;CUATRO&quot;
Case &quot;5&quot;
txtUnidaddecimal = &quot;CINCO&quot;
Case &quot;6&quot;
txtUnidaddecimal = &quot;SEIS&quot;
Case &quot;7&quot;
txtUnidaddecimal = &quot;SIETE&quot;
Case &quot;8&quot;
txtUnidaddecimal = &quot;OCHO&quot;
Case &quot;9&quot;
txtUnidaddecimal = &quot;NUEVE&quot;
End Select
End If
If Decenadecimal = 0 And Unidaddecimal = 0 Then
ConvierteDecimal = &quot;&quot;
Else
ConvierteDecimal = txtDecenadecimal & txtUnidaddecimal
End If
End Function
Function dolares(Rcantidad As Double) As String
Dim Rcant As String
Dim cAux As String
Dim Runi As String
Dim Rdec As String
Dim rdecs As String
Dim rcen As String
Dim riter As Integer
Dim rnum As String
Dim cDecim As String
&#39;Runi$ , Rdec$, Rdecs$, Rcen$, Rnum$, Riter$
Rcant = &quot;&quot;
Runi = &quot; UN DOS TRES CUATROCINCO SEIS SIETE OCHO NUEVE &quot;
Rdec = &quot;DIEZ ONCE DOCE TRECE CATORCE QUINCE DIECISEIS DIECISIETEDIECIOCHO DIECINUEVE&quot;
rdecs = &quot; VEINTE TREINTA CUARENTA CINCUENTASESENTA SETENTA OCHENTA NOVENTA &quot;
rcen = &quot; DOS TRES CUATRO SEIS SETE OCHO NOVE &quot;
Rcant = Trim(Str(Rcantidad))
If InStr(1, Rcant, &quot;.&quot;) > 0 Then
&#39;cAux = Left(Rcant, InStr(1, Rcant, &quot;.&quot;) + 2)
cAux = cRound(Rcant, 2)
Rcant = cAux
If Mid(Rcant, Len(Rcant) - 1, 1) = &quot;.&quot; Then
Rcant = Rcant + &quot;0&quot;
Rcant = Space(12 - Len(Left(Rcant, Len(Rcant) - 3))) + Rcant
Else
Rcant = Space(12 - Len(Left(Rcant, Len(Rcant) - 3))) + Rcant
cDecim = Right(Rcant, 2)
End If
Else
cDecim = &quot;00&quot;
End If
rnum = Mid(Rcant, 1, 12)
Rcant = &quot;&quot;
If Len(rnum) < 12 Then
rnum = Space(12 - Len(rnum)) + rnum
End If
If Val(rnum) = 0 Then
Rcant = &quot;CERO DOLARES AMERICANOS &quot;
Else
riter = 1
While riter < 13
If Mid(rnum, riter, 1) <> &quot; &quot; And Mid(rnum, riter, 1) <> &quot;0&quot; Then
Select Case Mid(rnum, riter, 1)
Case &quot;1&quot;
If Mid(rnum, riter + 1, 2) = &quot;00&quot; Then
Rcant = Rcant + &quot;CIEN &quot;
Else
Rcant = Rcant + &quot;CIENTO &quot;
End If
Case &quot;5&quot;
Rcant = Rcant + &quot;QUINIENTOS &quot;
Case Else
Rcant = Rcant + RTrim(Mid(rcen, Val(Mid(rnum, riter, 1)) * 6 + 1, 6)) + &quot;CIENTOS &quot;
End Select
End If
If Mid(rnum, riter + 1, 1) <> &quot; &quot; And Mid(rnum, riter + 1, 1) <> &quot;0&quot; Then
Select Case Mid(rnum, riter + 1, 1)
Case &quot;1&quot;
Rcant = Rcant + RTrim(Mid(Rdec, Val(Mid(rnum, riter + 2, 1)) * 10 + 1, 10)) + &quot; &quot;
Case &quot;2&quot;
If Mid(rnum, riter + 2, 1) = &quot;0&quot; Then
Rcant = Rcant + &quot;VEINTE &quot;
Else
Rcant = Rcant + &quot;VEINTI&quot; + RTrim(Mid(Runi, Val(Mid(rnum, riter + 2, 1)) * 6 + 1, 6)) + &quot; &quot;
End If
Case Else
Rcant = Rcant + RTrim(Mid(rdecs, Val(Mid(rnum, riter + 1, 1)) * 9 + 1, 9))
If Mid(rnum, riter + 2, 1) > &quot;0&quot; Then
Rcant = Rcant + &quot; Y &quot; + RTrim(Mid(Runi, Val(Mid(rnum, riter + 2, 1)) * 6 + 1, 6)) + &quot; &quot;
Else
Rcant = Rcant + &quot; &quot;
End If
End Select
End If
If Mid(rnum, riter + 2, 1) <> &quot; &quot; And Mid(rnum, riter + 1, 1) < &quot;1&quot; And Mid(rnum, riter + 1, 2) <> &quot;00&quot; Then
Rcant = Rcant + RTrim(Mid(Runi, Val(Mid(rnum, riter + 2, 1)) * 6 + 1, 6)) + &quot; &quot;
End If
Select Case riter
Case 1
If Mid(rnum, 1, 3) <> Space(3) And Mid(rnum, 1, 3) <> &quot;000&quot; Then
Rcant = Rcant + &quot;MIL &quot;
End If
Case 4
If Mid(rnum, 1, 6) <> Space(6) And Mid(rnum, 1, 6) <> &quot;000000&quot; Then
If Mid(rnum, 1, 6) <> Space(5) + &quot;1&quot; Then
Rcant = Rcant + &quot;MILLONES &quot;
Else
Rcant = Rcant + &quot;MILLON &quot;
End If
End If
Case 7
If Mid(rnum, 1, 9) <> Space(9) And Mid(rnum, 7, 3) <> &quot;000&quot; Then
Rcant = Rcant + &quot;MIL &quot;
End If
End Select
riter = riter + 3
Wend
If rnum = Space(11) + &quot;1&quot; Then
Rcant = Rcant + &quot;DOLAR AMERICANO &quot;
Else
If Mid(rnum, 7, 6) = &quot;000000&quot; Then
Rcant = Rcant + &quot;DE DOLARES AMERICANOS &quot;
Else
Rcant = Rcant + &quot;DOLARES AMERICANOS &quot;
End If
End If
End If
Rcant = LTrim(RTrim((Rcant + cDecim + &quot;/100 USD&quot;)))
dolares = Rcant
End Function
Añade un comentario a esta respuesta
Añade tu respuesta
Haz clic para o
Escribe tu mensaje