Quem sou eu

Minha foto
são paulo, são paulo, Brazil
apaixonado de mais por @fabricia sousa

chaveiro zona sul

desde de chaves simples até chave automotivas de alta tecnologia, Situada na Rua Monforte de Lemos,...
Curtir · Jean Alves curtiu isso.

jean alves - a compatibilidade com o genio!!!!

segunda-feira, 14 de novembro de 2011

formatando data


Data (I)

a = len(textbox1)
if a = 2 then
textbox1=textbox1 & a
else
a = len(textbox1)
if a = 5 then
textbox1=textbox1 & a
else
end if
end if
len conta os caracteres assim quado tiver dois caract ele coloca a barra e quado tivercinco caract ele coloca tambem ... 



DATA(II)
ActiveCell.Offset(0, 2).Value = CDate(Me.TextBox4)
ActiveCell.NumberFormat = "dd/mm/yy"

Quanto às barras você deve fazer o seguinte:

1. No evento Change coloque este código. Observeque TextBox4.
Private Sub TextBox4_Change()
Select Case Len(TextBox4)
Case 1
If TextBox4 = "/" Then TextBox4 =""
Case 2, 5
If Right(TextBox4, 1) <> "/" Then
TextBox4 = TextBox4 & "/"
Else
TextBox4 = Left(TextBox4, Len(TextBox4) - 1)
End If
Case Is > 10
TextBox4 = Left(TextBox4, 10)
End Select
End Sub

2 - No evento KeyPress o código abaixo vaipermitir apenas a entrda de numeros.

Private Sub TextBox4_KeyPress(ByVal KeyAscii AsMSForms.ReturnInteger)
Dim strValid As String
strValid = "0123456789"
If InStr(strValid, Chr(KeyAscii)) = 0 Then
KeyAscii = 0
End If
End Sub


 

TELEFONE(I)
If Len(TextBox1) = 2 Then TextBox1 = "("& Mid(TextBox1, 1, 2) & ")"
If Len(TextBox1) = 8 Then TextBox1 = TextBox1& "-"

CNPJ
If Len(TextBox2) = 2 Then TextBox2 = TextBox2& "."
If Len(TextBox2) = 6 Then TextBox2 = TextBox2& "."
If Len(TextBox2) = 10 Then TextBox2 = TextBox2& "/"
If Len(TextBox2) = 15 Then TextBox2 = TextBox2& "."

Não esquece de limitar os caracteres naspropriedades do TextBox (contando as pontuações)


TELEFONE(II)
Private SubTextBox1_Exit(ByVal Cancel As MSForms.ReturnBoolean)
TextBox1.Text = Format(TextBox1.Text,"00-00000000")
End Sub


CPF
Private Sub TextBox1_Change()

If Len(TextBox1) = 3 Then
TextBox1 = TextBox1 + "."
TextBox1.SelStart = 5
End If
If Len(TextBox1) = 7 Then
TextBox1 = TextBox1 + "."
TextBox1.SelStart = 9
End If
If Len(TextBox1) = 11 Then
TextBox1 = TextBox1 + "-"
TextBox1.SelStart = 14
End If
End Sub

Depois, é só você limitar o número de caracteres do textbox...

Valeu 
Imagem

Nenhum comentário:

Postar um comentário