Texbox a girilen sayı ve kontrol

Katılım
28 Kasım 2007
Mesajlar
919
Excel Vers. ve Dili
Office 2010 İngilizce
Kod:
Private Sub KAYIT_Click()
If TextBox1 = "" Then
    TextBox2 = ""
    MsgBox "TUTAR GİRİNİZ"
    TextBox1.SetFocus
    Exit Sub
End If

If TextBox2 = "" Then
    TextBox1 = " "
    MsgBox " VADE GİRİNİZ"
    TextBox1.SetFocus
    Exit Sub
End If

Cells([a65536].End(3).Row, "A").Select
ActiveCell.Offset(1, 0).Value = TextBox1.Text
ActiveCell.Offset(1, 1).Value = TextBox2.Text
Cells([a65536].End(3).Row + 1, "A").Select
TextBox1.Value = " "
TextBox2.Value = " "
TextBox3.Text = Range("d1")
TextBox4.Text = Range("E1")

TextBox1.SetFocus
End Sub
Merhaba arkadaşlar,

Yukarıdaki kod ile Textbox1 (tutar) ve textbox2(tarih) den kayıt yapıyorum. Fakat eğer textbox1 e tarih yada textbox2 ye sayı girilmek istendiğinde mesaj verdirebilirmiyim.
 
Katılım
22 Nisan 2005
Mesajlar
486
Excel Vers. ve Dili
tarkan@tarkanvural.com.tr
Kod:
Private Sub KAYIT_Click()
If TextBox1.Text = Empty Or TextBox2.Text = Empty Then
    MsgBox "Lütfen Tüm Alanları Doldurunuz"
    Exit Sub
End If
Range("a65536").End(3)(2, 1).Value = TextBox1.Value
Range("a65536").End(3)(1, 2).Value = TextBox2.Value
TextBox1.Value = Empty
TextBox2.Value = Empty
MsgBox "Kaydedildi"
End Sub

Private Sub TextBox1_Change()
If TextBox1.Value = Empty Then Exit Sub
If Not IsNumeric(Mid(TextBox1.Value, Len(TextBox1.Value), 1)) Then
MsgBox "Lütfen sayısal veri giriniz"
TextBox1.Value = Mid(TextBox1.Value, 1, Len(TextBox1.Value) - 1)
End If
End Sub

Private Sub TextBox2_Change()
Select Case Len(TextBox2.Value)
    Case Is = 2, 5
        TextBox2.Value = TextBox2.Value & "."
    Case Is = 10
        KAYIT_Click
        TextBox1.SetFocus
End Select
End Sub
 
Katılım
28 Kasım 2007
Mesajlar
919
Excel Vers. ve Dili
Office 2010 İngilizce
Private Sub TextBox2_Change()
If TextBox2.Value = Empty Then Exit Sub
If Not IsDate(Mid(TextBox2.Value, Len(TextBox2.Value), 1)) Then
MsgBox "Lütfen TARİH giriniz"
TextBox2.Value = Mid(TextBox2.Value, 1, Len(TextBox2.Value) - 1)
End If
End Sub
TEXTBOX2 ye de tarih kontrolü koymaya çalıştım sizin kodlardan ama olmuyor. Textbox 2 ye tarih dışında birşey girilmesini engellemek için ne yapmam gerekiyor.
 
Katılım
22 Nisan 2005
Mesajlar
486
Excel Vers. ve Dili
tarkan@tarkanvural.com.tr
Bunun için DTPicker nesnesi daha kullanışlıdır aslında.
Yine de denemek isterseniz aşağıdaki kodları inceleyiniz.

Kod:
Private Sub TextBox2_Change()
If TextBox2.Value = Empty Then Exit Sub
Select Case Len(TextBox2.Value)
Case Is = 2, 5
    TextBox2.Value = TextBox2.Value & "."
Case Is = 10
    CommandButton1.SetFocus
Case Else
    If Not IsNumeric(TextBox2.Value) Then
        TextBox2.Value = Mid(TextBox2.Value, 1, Len(TextBox2.Value) - 1)
        MsgBox "Lütfen TARİH giriniz"
    End If
End Select
End Sub

Private Sub TextBox2_Exit(ByVal Cancel As MSForms.ReturnBoolean)
If Not IsDate(TextBox2.Value) Then
    MsgBox "Lütfen Geçerli Bir Tarih Giriniz"
    TextBox2.Value = Empty
End If
End Sub
 

Ekli dosyalar

Katılım
28 Kasım 2007
Mesajlar
919
Excel Vers. ve Dili
Office 2010 İngilizce
Teşekkürler oldu üstadım. Fakat sizin textbox1 için yazdığınız kodda normal bir sayı yazdığımda problem yok mesala 1.500 gibi, ama 1.500,50 yazdığımda lütfen sayısal değer giriniz diyor.
Private Sub TextBox1_Change()
If TextBox1.Value = Empty Then Exit Sub
If Not IsNumeric(Mid(TextBox1.Value, Len(TextBox1.Value), 1)) Then
MsgBox "Lütfen sayısal veri giriniz"
TextBox1.Value = Mid(TextBox1.Value, 1, Len(TextBox1.Value) - 1)
End If
End Sub
Private Sub TextBox1_Exit(ByVal Cancel As MSForms.ReturnBoolean)
TextBox1.Value = Format(TextBox1, "0.00")
End Sub
 
Katılım
7 Ağustos 2007
Mesajlar
328
Excel Vers. ve Dili
excell 2003 - 2007
arkadaşlar yapılanlar genel itibari ile çalışıyor ama gün sayısı verilmediğinde sorun çıkarıyor.

Private Sub UserForm_Initialize()
TrhBox = Format(Date)
End Sub
Private Sub aktar_Click()
Set s1 = Sheets("İB")
Set s2 = Sheets("SSK İG")

s1.Range("B10:B13").Clear

'TARİH HESAPLAMA
trh1 = Format(Date + IstGsBox - 1)
trh2 = Format(Date + IstGsBox)

'İŞE BAŞLAMA
s1.Range("B5") = SclBox
s1.Range("B5").Font.Size = 12
s1.Range("B6") = AdBox & Chr(32) & SoyadBox
s1.Range("B6").Font.Size = 12
s1.Range("B6").Font.Bold = True
s1.Range("B7") = TrhBox
s1.Range("B7").Font.Size = 12
s1.Range("B9") = TshsBox
s1.Range("B10").Font.Size = 12

'ŞARTLI DALLANMA1
If RctBox.Value = "" Then
Else
s1.Range("B10") = RctBox
s1.Range("B10").Font.Size = 12
End If

'ŞARTLI DALLANMA2
If IstGsBox.Value = "" Then
s1.Range("B12") = TrhBox
s1.Range("B12").Font.Size = 12
s1.Range("B13") = TrhBox & Chr(32) & Chr(32) & SaatBox
s1.Range("B13").Font.Size = 12
Else
s1.Range("B11") = IstGsBox & Chr(32) & Chr(40) & yaz(IstGsBox) & Chr(41) & Chr(32) & "GÜN İSTİRAHATİ UYGUN GÖRÜLMÜŞTÜR."
s1.Range("B11").Font.Size = 12
s1.Range("B12") = trh1
s1.Range("B12").Font.Size = 12
s1.Range("B13") = trh2
s1.Range("B13").Font.Size = 12
End If

s1.Range("F1") = PrtklBox
s1.Range("F1").Font.Size = 12
s1.Range("F1").Font.Bold = True
End Sub

trh1 = Format(Date + IstGsBox - 1)
trh2 = Format(Date + IstGsBox)
burada gün sayısı girersem işlem normal çalışıyor

If IstGsBox.Value = "" Then
s1.Range("B12") = TrhBox
s1.Range("B12").Font.Size = 12
s1.Range("B13") = TrhBox & Chr(32) & Chr(32) & SaatBox
s1.Range("B13").Font.Size = 12
eğer hücre boşsa sadece günün tarihin ve belirttiğim saati yazacak
değilse (Else işlevi sayı girdiğimde çalışıyor burada sorun yok)
s1.Range("B11") = IstGsBox & Chr(32) & Chr(40) & yaz(IstGsBox) & Chr(41) & Chr(32) & "GÜN İSTİRAHATİ UYGUN GÖRÜLMÜŞTÜR."
s1.Range("B11").Font.Size = 12
s1.Range("B12") = trh1
s1.Range("B12").Font.Size = 12
s1.Range("B13") = trh2
s1.Range("B13").Font.Size = 12

istirahat gün sayısıyla günün tarihinin bir eksiğini yazıyor, alt satıra da gün sayısı kadar toplayıp yazıyor. Herhangi bir değer girmezsem hata veriyor sebebi ne olabilir
Yardımlarınız bekliyorum, teşekkür ederim.
 
Son düzenleme:

Orion1

Uzman
Uzman
Katılım
1 Mart 2005
Mesajlar
22,239
Excel Vers. ve Dili
Win7 Home Basic TR 64 Bit

Ofis-2010-TR 32 Bit
Teşekkürler oldu üstadım. Fakat sizin textbox1 için yazdığınız kodda normal bir sayı yazdığımda problem yok mesala 1.500 gibi, ama 1.500,50 yazdığımda lütfen sayısal değer giriniz diyor.
Textboxta yazarken önceki yazdığınız nokta ile virgülün yerlerini değiştirn.Çünkü sizinki ingilizce ingilizcede ondalıklar nokta binlik ayıraçlar virgül olur.:cool:
 
Üst