Este fórum está sendo desativado

Depois de 9 anos, este fórum será desativado. Mas calma.... estamos migrando para uma comunidade no DISCORD. Junte-se a nós.

ENTRAR PARA DISCORD

Tópicos relacionados a códigos VBA, gravação de macros, etc.
  • Avatar do usuário
Por FRF
Posts
#31789
Pessoal, boa noite!


Tenho uma dúvida sobre o separador de mihar no VBA.

Por exemblo, se eu digitar um numero em um textbox de uma useform sem separador de mihar.
Sendo ele 1000, 10000 ou 1000000.
Como posso usar a função Format para colocar apenas o separador de milhar sem colocar numeros decimais?
Avatar do usuário
Por fcarlosc2018
Posts Avatar
#31791
Boa-noite

Tente assim:

Private Sub TextBox1_AfterUpdate()

On Error Resume Next
'Me.TextBox1 = FormatNumber(Me.TextBox1)
TextBox1 = Format(TextBox1, "R$ #,###0.00")

End Sub

Private Sub TextBox1_Change()

If Not IsNumeric(TextBox11.Text) Then TextBox11.Text = Empty

Valor = TextBox1.Value

If IsNumeric(Valor) Then
If InStr(1, Valor, "-") >= 1 Then Valor = Replace(Valor, "-", "") 'retira sinal negativo
If InStr(1, Valor, ",") >= 1 Then Valor = CDbl(Replace(Valor, ",", "")) 'retirar a virgula
'If InStr(1, valor, ".") >= 1 Then valor = Replace(valor, ".", "") 'para trabalhar melhor retiramos ponto
Select Case Len(Valor) 'verifica casas para inserção de ponto
Case 1
numPonto = "00" & Valor
Case 2
numPonto = "0" & Valor
Case 6 To 8
numPonto = Left(Valor, Len(Valor) - 5) & "." & Right(Valor, 5)
Case 9 To 11
numPonto = inseriPonto(8, Valor)
Case 12 To 14
numPonto = inseriPonto(11, Valor)
Case Else
numPonto = Valor
End Select
numVirgula = Left(numPonto, Len(numPonto) - 2) & "," & Right(numPonto, 2)

TextBox1.Value = numVirgula

Else
If Valor = "" Then Exit Sub
MsgBox "Número invalido", vbCritical, "Caracter Invalido"
Exit Sub
End If

End Sub


Function inseriPonto(inicio, Valor)

i = Left(Valor, Len(Valor) - inicio)
M1 = Left(Right(Valor, inicio), 3)
M2 = Left(Right(Valor, 8), 3)
F = Right(Valor, 5)

If (M2 = M1) And (Len(Valor) < 12) Then
inseriPonto = i & "." & M1 & "." & F

Else

inseriPonto = i & "." & M1 & "." & M2 & "." & F

End If

End Function
Por FRF
Posts
#31814
Boa tarde fcarlos2018.

Muito obrigado pela resposta.

Mas já consegui resolver de uma outra maneira.
long long title how many chars? lets see 123 ok more? yes 60

We have created lots of YouTube videos just so you can achieve [...]

Another post test yes yes yes or no, maybe ni? :-/

The best flat phpBB theme around. Period. Fine craftmanship and [...]

Do you need a super MOD? Well here it is. chew on this

All you need is right here. Content tag, SEO, listing, Pizza and spaghetti [...]

Lasagna on me this time ok? I got plenty of cash

this should be fantastic. but what about links,images, bbcodes etc etc? [...]

Estamos migrando para uma comunidade no Discord