Excel planilha vba numeros por extenso ate 9999

Qui, 25 de Novembro de 2010 18:23 Expedito Marcondes
Imprimir

Saberexcel o site de quem precisa aprender Macros Microsoft Excel VBA

Essa Função do Aplicativo Microsoft Excel VBA, insere números por extenso até 9.999

Function Escr(n)
Unid = Array("", "Um", "Dois", "Três", "Quatro", "Cinco", _
"Seis", "Sete", "Oito", "Nove", "Dez", "Onze", "Doze", _
"Treze", "Quatorze", "Quinze", "Dezesseis", "Dezessete", _
"Dezoito", "Dezenove", "Vinte")
Dezen = Array("", "Dez", "Vinte", "Trinta", "Quarenta", _
"Cinquenta", "Sessenta", "Setenta", "Oitenta", "Noventa")
Centen = Array("", "Cento", "Duzentos", "Trezentos", _
"Quatrocentos", "Quinhentos", "Seiscentos", _
"Setecentos", "Oitocentos", "Novecentos", "Mil")
Num = n
Escr = ""
If n = 0 Then
Escr = "Zero"
End If
If (n \ 1000) > 0 And n \ 1000 < 10 Then
Escr = Unid(n \ 1000) & " Mil "
End If
n = n - (n \ 1000) * 1000
If n > 100 Then
Escr = Escr & Centen(n \ 100)
End If
If n = 100 Then
Escr = Escr & " Cem"
GoTo Prossiga
End If
n = n - (n \ 100) * 100
If n >= 20 And n < 100 Then
Escr = Escr & " " & Dezen(n \ 10)
End If
If n > 0 And n < 20 Then
Escr = Escr & " " & Unid(n)
GoTo Prossiga
End If
n = n - (n \ 10) * 10
If n > 0 Then
Escr = Escr & " " & Unid(n)
End If
Prossiga:
If Num Mod 10 <> 0 Then
If InStr(1, Escr, "Vinte", 1) = 0 Then
If InStr(1, Escr, "Trinta", 1) = 0 Then
If InStr(1, Escr, "enta", 1) > 0 Then
Escr = Application.Substitute(Escr, "enta", "enta e ")
End If
End If
End If
End If
If Num Mod 10 <> 0 Then
If InStr(1, Escr, "Vinte", 1) > 0 Then
If InStr(1, Escr, "Trinta", 1) = 0 Then
If InStr(1, Escr, "enta", 1) = 0 Then
Escr = Application.Substitute(Escr, "Vinte", "Vinte e ")
End If
End If
End If
End If
If Num Mod 10 <> 0 Then
If InStr(1, Escr, "Vinte", 1) = 0 Then
If InStr(1, Escr, "Trinta", 1) > 0 Then
If InStr(1, Escr, "enta", 1) = 0 Then
Escr = Application.Substitute(Escr, "Trinta", "Trinta e ")
End If
End If
End If
End If
If Num Mod 100 <> 0 Then
If InStr(1, Escr, "ento", 1) > 0 Then
Escr = Application.Substitute(Escr, "Cento", "Cento e ")
End If
End If
If Num Mod 100 <> 0 Then
If InStr(1, Escr, "entos", 1) > 0 Then
Escr = Application.Substitute(Escr, "entos", "entos e ")
End If
End If
If Num Mod 1000 <> 0 Then
If (Num - (Num \ 1000) * 1000) <= 100 Then
If InStr(1, Escr, "Mil", 1) > 0 Then
Escr = Application.Substitute(Escr, "Mil", "Mil e ")
End If
End If
End If

End Function



Aprenda tudo sobre planilhas do Aplicativo Microsoft Excel VBA(Visual Basic Application), sozinho, com baixo custo, praticando com os produtos didáticos Saberexcel



 

  Baixe o exemplo de planilha contendo a função extenso acima
Excel planilha vba numeros por extenso ate 9999 (20.9 kB)




Compre com segurança, garantia e ótimos preços nas lojas SubMarino Informática - Submarino.com.br

Tags:
Última atualização em Dom, 14 de Agosto de 2011 12:42