Bir önceki benzer veriyi sorgulama

Katılım
12 Eylül 2020
Mesajlar
174
Excel Vers. ve Dili
365 ev
Merhabalar
Userforma kopyalayınız

Kod:
Private Sub TextBox2_BeforeUpdate(ByVal Cancel As MSForms.ReturnBoolean)
    Dim bul As Range
 
    Set bul = Sayfa1.Range("B:B").Find(ComboBox1.Value, searchDirection:=xlPrevious)
    If Not bul Is Nothing Then
     
        If bul.Offset(0, 2).Value > CLng(TextBox2.Value) Then
            MsgBox "Değer küçük"
            Cancel = True
            Exit Sub
        End If
    End If
 
End Sub
Çok sade olmuş teşekkürler fakat numerik veri girmediğimde type mismatch hatası alıyorum
 
Katılım
4 Nisan 2006
Mesajlar
999
Excel Vers. ve Dili
OFFICE 2021 Türkçe
Merhabalar
Bu şekilmi istiyorsun

Kod:
Private Sub TextBox2_BeforeUpdate(ByVal Cancel As MSForms.ReturnBoolean)
    Dim bul As Range
 
    Set bul = Sayfa1.Range("B:B").Find(ComboBox1.Value, searchDirection:=xlPrevious)
    
    If IsNumeric(TextBox2.Value) Then
        If Not bul Is Nothing Then
            
            If bul.Offset(0, 2).Value > CLng(TextBox2.Value) Then
                MsgBox "Değer küçük"
                Cancel = True
                Exit Sub
            End If
        Else
            Cancel = False
        End If
    Else
        Cancel = True
        MsgBox "Sayısal değer giriniz."
    End If
 
End Sub
 
Katılım
12 Eylül 2020
Mesajlar
174
Excel Vers. ve Dili
365 ev
Merhabalar
Bu şekilmi istiyorsun

Kod:
Private Sub TextBox2_BeforeUpdate(ByVal Cancel As MSForms.ReturnBoolean)
    Dim bul As Range

    Set bul = Sayfa1.Range("B:B").Find(ComboBox1.Value, searchDirection:=xlPrevious)
   
    If IsNumeric(TextBox2.Value) Then
        If Not bul Is Nothing Then
           
            If bul.Offset(0, 2).Value > CLng(TextBox2.Value) Then
                MsgBox "Değer küçük"
                Cancel = True
                Exit Sub
            End If
        Else
            Cancel = False
        End If
    Else
        Cancel = True
        MsgBox "Sayısal değer giriniz."
    End If

End Sub
hayır hayır , normalde km değerleri giriyorum textbox2 ye fakat bazı durumlarda özel ad yazdığım oluyor yani bildiğimiz düz text , bu gibi durumlarda mesela

16 abc 123 plakalı araca 55 litre mazot 12345 km yazıyorum , bir sıkıntı yok işliyor
16 abc 123 plakalı araca x litre mazot km yerinede " özel ad" (ahmet,mehmet) yazdığım zaman döngüye girip ahmet 12345 ten küçük diyor mesela demesin istiyorum yani numerik değer girildiğinde karşılaştırma yapsın , string şeklinde "ahmet" yazdığımda direkt yazsın istiyorum
 

Korhan Ayhan

Administrator
Yönetici
Admin
Katılım
15 Mart 2005
Mesajlar
42,243
Excel Vers. ve Dili
Microsoft 365 Tr-En 64 Bit
Diyelim ki aynı plakaya önce sayısal değerler girip kayıt ettiniz. Sonra metinsel dediğiniz ifade girip kayıt ettiniz.

3. kayıt işleminde aynı plakanın son km bilgisi metin olmayan satırdaki değeri mi almak istiyorsunuz?
 
Katılım
12 Eylül 2020
Mesajlar
174
Excel Vers. ve Dili
365 ev
Diyelim ki aynı plakaya önce sayısal değerler girip kayıt ettiniz. Sonra metinsel dediğiniz ifade girip kayıt ettiniz.

3. kayıt işleminde aynı plakanın son km bilgisi metin olmayan satırdaki değeri mi almak istiyorsunuz?
evet 3. kayıt işleminde eğer km giriyorsam km değerlerini baz alarak tarama yapmasını istiyorum aksi takdirde metin değeri ve sayısal değeri ayırt ettiremiyorum zaten eğer metin değeri girdiysem zaten herhangi bir tarama yapmasına gerek yok, sizi de yoruyorum ramazan ramazan :)
 

Korhan Ayhan

Administrator
Yönetici
Admin
Katılım
15 Mart 2005
Mesajlar
42,243
Excel Vers. ve Dili
Microsoft 365 Tr-En 64 Bit
Mazot miktarı farklı KM aynı ise durum ne olacak peki?

Kod şu anki haliyle üstte ki koşula müsade ediyor.

#16 nolu mesajımda ki kodu tekrar revize ettim. Şimdi biraz daha hızlı işlem yapıyor. Deneyiniz.
 
Katılım
4 Nisan 2006
Mesajlar
999
Excel Vers. ve Dili
OFFICE 2021 Türkçe
Merhabalar

Kontrol edermisiniz

Kod:
Private Sub TextBox2_BeforeUpdate(ByVal Cancel As MSForms.ReturnBoolean)
    Dim bul As Range
    Dim ilkadres As String
    Dim km As Long
    Dim metinsel As Boolean
    
    
    Set bul = Sayfa1.Range("B2:B50000").Find(ComboBox1.Value, searchDirection:=xlPrevious)
    
    If Not bul Is Nothing Then
        ilkadres = bul.Address
        Do
             Set bul = Sayfa1.Range("B2:B50000").FindPrevious(bul)
             If IsNumeric(bul.Offset(0, 2).Value) Then Exit Do
             If ilkadres = bul.Address Then metinsel = True
        Loop Until ilkadres = bul.Address
        
        If Not metinsel Then
            If IsNumeric(TextBox2.Value) Then
                If bul.Offset(0, 2).Value > CLng(TextBox2.Value) Then
                    MsgBox "Değer küçük"
                    Cancel = True
                End If
            End If
        End If
          
    End If

End Sub
 
Katılım
12 Eylül 2020
Mesajlar
174
Excel Vers. ve Dili
365 ev
Mazot miktarı farklı KM aynı ise durum ne olacak peki?

Kod şu anki haliyle üstte ki koşula müsade ediyor.

#16 nolu mesajımda ki kodu tekrar revize ettim. Şimdi biraz daha hızlı işlem yapıyor. Deneyiniz.
normalde böyle bir durumla karşılaşmam diye hesapladım ama

Herhangi bir sıkıntı yaşamadım , kod güzelce çalıştı. Teşekkürler.
 
Son düzenleme:
Katılım
4 Nisan 2006
Mesajlar
999
Excel Vers. ve Dili
OFFICE 2021 Türkçe
Merhabalar
Tekrar düzelte yaptım
Denermisiniz
Kod:
Private Sub TextBox2_BeforeUpdate(ByVal Cancel As MSForms.ReturnBoolean)
    Dim bul As Range
    Dim ilkadres As String
    Dim km As Long
    Dim metinsel As Boolean
    
    
    Set bul = Sayfa1.Range("B2:B50000").Find(ComboBox1.Value, searchDirection:=xlPrevious)
      
    If Not bul Is Nothing Then
        ilkadres = bul.Address
        Do
             Set bul = Sayfa1.Range("B2:B50000").FindPrevious(bul.Offset(1, 0))
             If IsNumeric(bul.Offset(0, 2).Value) Then Exit Do
             If ilkadres = bul.Offset(1, 0).Address Then metinsel = True
        Loop Until ilkadres = bul.Address
        
        If Not metinsel Then
            If IsNumeric(TextBox2.Value) Then
                If bul.Offset(0, 2).Value > CLng(TextBox2.Value) Then
                    MsgBox "Değer küçük"
                    Cancel = True
                    Exit Sub
                End If
                End If
        End If
          
    End If

    
End Sub
 
Son düzenleme:
Katılım
4 Nisan 2006
Mesajlar
999
Excel Vers. ve Dili
OFFICE 2021 Türkçe
Son hali
Kod:
Private Sub TextBox2_BeforeUpdate(ByVal Cancel As MSForms.ReturnBoolean)
    Dim bul As Range
    Dim ilkadres As String
    Dim km As Long
    Dim metinsel As Boolean
    
    
    Set bul = Sayfa1.Range("B2:B50000").Find(ComboBox1.Value, searchDirection:=xlPrevious)
      
    If Not bul Is Nothing Then
        ilkadres = bul.Address
        Do
             Set bul = Sayfa1.Range("B2:B50000").FindPrevious(bul)
             If IsNumeric(bul.Offset(1, 2).Value) Then Exit Do
            
        Loop Until ilkadres = bul.Address
        
        If ilkadres <> bul.Address Then
      
            If IsNumeric(TextBox2.Value) Then
                If bul.Offset(0, 2).Value > CLng(TextBox2.Value) Then
                    MsgBox "Değer küçük"
                    Cancel = True
                    Exit Sub
                End If
                End If
        End If
          
    End If

    
End Sub
 
Son düzenleme:
Katılım
4 Nisan 2006
Mesajlar
999
Excel Vers. ve Dili
OFFICE 2021 Türkçe
Merhabalar
Düzeltilmiş son hali
Userforma kopyalayınız



Kod:
Private Sub TextBox2_BeforeUpdate(ByVal Cancel As MSForms.ReturnBoolean)
    Dim bul As Range
    Dim ilkadres As String
    Dim km As Long
    Dim metinsel As Boolean
    Dim sonuc As Boolean
   
    Set bul = Sayfa1.Range("B2:B50000").Find(ComboBox1.Value, searchDirection:=xlPrevious)
     
    If Not bul Is Nothing Then
     
        ilkadres = bul.Address
        Do
           
             If IsNumeric(bul.Offset(0, 2).Value) Then
                metinsel = False
                km = bul.Offset(0, 2).Value
                Exit Do
             End If
             Set bul = Sayfa1.Range("B2:B50000").FindPrevious(bul)
             metinsel = True
        Loop Until ilkadres = bul.Address
       
        If Not metinsel Then
            If IsNumeric(TextBox2.Value) Then
                If km > CLng(TextBox2.Value) Then
                    Cancel = True
                    MsgBox "Deger küçük"
                    Exit Sub
                End If
            End If
        End If

    End If
   
End Sub
 
Katılım
12 Eylül 2020
Mesajlar
174
Excel Vers. ve Dili
365 ev
Merhabalar
Düzeltilmiş son hali
Userforma kopyalayınız



Kod:
Private Sub TextBox2_BeforeUpdate(ByVal Cancel As MSForms.ReturnBoolean)
    Dim bul As Range
    Dim ilkadres As String
    Dim km As Long
    Dim metinsel As Boolean
    Dim sonuc As Boolean
  
    Set bul = Sayfa1.Range("B2:B50000").Find(ComboBox1.Value, searchDirection:=xlPrevious)
    
    If Not bul Is Nothing Then
    
        ilkadres = bul.Address
        Do
          
             If IsNumeric(bul.Offset(0, 2).Value) Then
                metinsel = False
                km = bul.Offset(0, 2).Value
                Exit Do
             End If
             Set bul = Sayfa1.Range("B2:B50000").FindPrevious(bul)
             metinsel = True
        Loop Until ilkadres = bul.Address
      
        If Not metinsel Then
            If IsNumeric(TextBox2.Value) Then
                If km > CLng(TextBox2.Value) Then
                    Cancel = True
                    MsgBox "Deger küçük"
                    Exit Sub
                End If
            End If
        End If

    End If
  
End Sub
Bu da çalışıyor , emeğinize sağlık
 
Üst