AccessTr.neT
Excel Vba İle Userform Üzerinden Kayıt Silme Hakkında. - Baskı Önizleme

+- AccessTr.neT (https://accesstr.net)
+-- Forum: Microsoft Excel (https://accesstr.net/forum-microsoft-excel.html)
+--- Forum: Excel Cevaplanmış Soruları (https://accesstr.net/forum-excel-cevaplanmis-sorulari.html)
+--- Konu Başlığı: Excel Vba İle Userform Üzerinden Kayıt Silme Hakkında. (/konu-excel-vba-ile-userform-uzerinden-kayit-silme-hakkinda.html)

Sayfalar: 1 2 3 4 5


RE: Excel Vba İle Userform Üzerinden Kayıt Silme Hakkında. - berduş - 26/04/2021

gerçi soru çözüldü ama farklı bir yöntem buldum onu da eklemek istedim
Not1: aslında her silmeden sonra firmaunvan açılır kutusu güncellenmeli
Not2: bu kadar az veriyle hızını kontrol edemedim hızla ilgili bilgi verirseniz sevinirim
Sub KytSil(ByVal IDBul As String)

Dim tbl As ListObject
Dim Sonuc As Range
Dim IDBul As String

With ThisWorkbook.Worksheets("ana_sayfa")
 
  Set tbl = .ListObjects("Tablo1")

'1. sütunda veri arama
  On Error Resume Next
  Set Sonuc = tbl.DataBodyRange.Columns(1).Find(IDBul, LookAt:=xlWhole)
  On Error GoTo 0

'bulunan verini silinmesi
        .Unprotect "171717"
            If Not Sonuc Is Nothing Then
              xTblBul = tbl.ListRows(Sonuc.row - tbl.HeaderRowRange.row).Index
              tbl.ListRows(xTblBul).Delete
            End If
        .Protect "171717"
End With
End Sub



Re: Excel Vba İle Userform Üzerinden Kayıt Silme Hakkında. - berduş - 26/04/2021

kayıt silince combodan da o değeri silen kod eklenmiştir
ComboBox_FirmaUnvani.RemoveItem (Me.ComboBox_FirmaUnvani.ListIndex) '<== combodan değer silme
Private Sub btn_KayitSil_Click()
If Len(TextBox_ID & "") = 0 Then Exit Sub
If MsgBox("Veriler Silinecek, Emin misiniz...?", vbExclamation + vbYesNo, "Firma Tanımlama Formu") = vbNo Then Exit Sub

    With ThisWorkbook.Worksheets("Ana_Sayfa")
            KytSil (TextBox_ID)
            ComboBox_FirmaUnvani.RemoveItem (Me.ComboBox_FirmaUnvani.ListIndex) '<== combodan değer silme
            Call temizle
            TextBox_Tarih = Format(Date, "dd.mm.yyyy")
   
    End With
   
    TextBox_Tarih.SetFocus
       
    With TextBox_Tarih
                .SelStart = 0
                .SelLength = .TextLength
            End With
           
    btn_KayitEkle.Enabled = True
    
End Sub
Modüle eklenen kayıt silme kodu
Sub KytSil(ByVal IDBul As String)

Dim tbl As ListObject
Dim Sonuc As Range

With ThisWorkbook.Worksheets("ana_sayfa")
 
  Set tbl = .ListObjects("Tablo1")

'1. sütunda veri arama
  On Error Resume Next
  Set Sonuc = tbl.DataBodyRange.Columns(1).Find(IDBul, LookAt:=xlWhole)
  On Error GoTo 0

'bulunan verini silinmesi
        .Unprotect "171717"
            If Not Sonuc Is Nothing Then
              xTblBul = tbl.ListRows(Sonuc.row - tbl.HeaderRowRange.row).Index
              tbl.ListRows(xTblBul).Delete
            End If
        .Protect "171717"
End With
End Sub



RE: Excel Vba İle Userform Üzerinden Kayıt Silme Hakkında. - feraz - 26/04/2021

Buda alternatif olsun dictionary ve dizi ile Img-grin

Private Sub btn_KayitSil_Click()
    Dim dic As Object, i As Long
    Dim dizi, sonTabloSatr As Long, aranan
   
    If Len(Trim(TextBox_ID.Value)) = 0 Then Exit Sub
    If Len(Trim(ComboBox_FirmaUnvani.Value)) = 0 Then Exit Sub
    If MsgBox("Veriler Silinecek, Emin misiniz...?", vbExclamation + vbYesNo, "Firma Tanýmlama Formu") = vbNo Then Exit Sub

    With ThisWorkbook.Worksheets("Ana_Sayfa")
        sonTabloSatr = .Cells.Find("*", _
                                    SearchOrder:=xlByRows, LookIn:=xlValues, SearchDirection:=xlPrevious).Row
   
        If WorksheetFunction.CountA(.Range("A2:A" & Rows.Count)) = 0 Then Exit Sub
        If sonTabloSatr < 2 Then Exit Sub
        Set dic = CreateObject("scripting.dictionary")
        If WorksheetFunction.CountA(.Range("A2:A" & Rows.Count)) = 1 Then
            dic.Add CStr(.Range("A" & sonTabloSatr).Value), 2
        ElseIf WorksheetFunction.CountA(.Range("A2:A" & Rows.Count)) > 1 Then
            dizi = .Range("A2:A" & sonTabloSatr).Value
            For i = LBound(dizi) To UBound(dizi)
                aranan = CStr(dizi(i, 1))
                If dic.Exists(aranan) = False Then dic.Add aranan, i + 1
            Next
            Erase dizi
        End If
       
        If dic.Count = 0 Then Exit Sub
        .Unprotect "171717"
        .Rows(dic(CStr(Me.TextBox_ID.Value))).Delete
        UserForm_Initialize
        .Protect "171717"
        Call temizle
        TextBox_Tarih = Format(Date, "dd.mm.yyyy")
    End With
   
    TextBox_Tarih.SetFocus
       
    With TextBox_Tarih
                .SelStart = 0
                .SelLength = .TextLength
            End With
           
    btn_KayitEkle.Enabled = True
    Set dic = Nothing
    MsgBox "Kayit silindi..", vbInformation, "Bilgi"
End Sub



RE: Excel Vba İle Userform Üzerinden Kayıt Silme Hakkında. - Oğuz Türkyılmaz - 26/04/2021

Feraz Hocam Zahmet oldu size de ama anladım çok teşekkür ederin.


RE: Excel Vba İle Userform Üzerinden Kayıt Silme Hakkında. - Oğuz Türkyılmaz - 26/04/2021

Berduş hocam teşekkür ederim bende bu sorunu me.requery ile çözmeye çalışıyordum. Img-grin

Kodların en son halini bu şekilde düzenledim. Sorunsuz çalışıyor. Feraz hocam la sizin kodların mixini yapmış oldum gibi oldu. Img-grin Hız konusunda ilerde bilgi verebilirim ancak. Kodların bu şekliyle kayıtları girmeye yeni başlıyorum. Yeterince kayıt girdikten sonra hızda bir yavaşlama algılarsam mutlaka sizin ve feraz hocamın yeni kodlarıyla da deneme yapar bilgi veririm.

Kod:
Private Sub btn_KayitSil_Click()

If ComboBox_FirmaUnvani.Tag = "" Or TextBox_ID.Value = "" Then
    MsgBox "Firma Ünvanları Seçeneğinden Silmek İstediğiniz Kaydı Seçmelisiniz...", vbCritical, "Hata"
    
    Exit Sub
    End If

If MsgBox("Veriler Silinecek, Emin misiniz...?", vbExclamation + vbYesNo, "Firma Tanımlama Formu") = vbNo Then Exit Sub
    
    With ThisWorkbook.Worksheets("Ana_Sayfa")
    .Unprotect "171717"
    .Rows(ComboBox_FirmaUnvani.Tag).EntireRow.Delete
     ComboBox_FirmaUnvani.RemoveItem (Me.ComboBox_FirmaUnvani.ListIndex)
     ComboBox_FirmaUnvani.Tag = ""
    .Protect "171717"
     Call temizle
     TextBox_Tarih = Format(Date, "dd.mm.yyyy")
    
        
    End With
    TextBox_Tarih.SetFocus
    With TextBox_Tarih
        .SelStart = 0
        .SelLength = .TextLength
    End With
    btn_KayitEkle.Enabled = True
    
End Sub




RE: Excel Vba İle Userform Üzerinden Kayıt Silme Hakkında. - feraz - 26/04/2021

Hızda yavaşlama olmaz abey hiçbir kodda.