textboxda arat listboxda bul buton ile satırı sil

bilisim2010

Altın Üye
Katılım
2 Nisan 2011
Mesajlar
162
Excel Vers. ve Dili
office 2007 tr
Altın Üyelik Bitiş Tarihi
17-12-2025
merhaba textboxda aratıp listboxda çift tıklayarak seçiyorum seçili satırı bir buton ile silmeye çalışınca en üst satırı seçip siliyor seçtiğim satırı silmesini nasıl sağlarım aşağıdaki kodlar arama yapmadan seçtiğim satırı siliyor olay arama yapıp seçtiğim satırda patlıyor. lütfen yardımcı olun

Private Sub TextBox1_Change()
Dim Son As Long, Veri As Variant, X As Long

Son = WorksheetFunction.Max(3, S1.Cells(S1.Rows.Count, 1).End(3).Row)
Veri = S1.Range("A2:Q" & Son).Value

lstpersonel.Clear

ReDim Liste(1 To 16, 1 To 1)

For X = LBound(Veri, 1) To UBound(Veri, 1)
If UCase(Replace(Replace(Veri(X, 2), "ı", "I"), "i", "İ")) Like "*" & _
UCase(Replace(Replace(TextBox1, "ı", "I"), "i", "İ")) & "*" Then
Say = Say + 1
ReDim Preserve Liste(1 To 16, 1 To Say)
For y = 1 To 16
Liste(y, Say) = Veri(X, y)
Next
End If
Next

If Say > 0 Then
With lstpersonel
.ColumnCount = 16
.Column = Liste
.AddItem , 0
For X = 1 To 16
.List(0, X - 1) = S1.Cells(1, X).Value
Next
.ListIndex = 0
End With

TextBox1.BackColor = &H80000005
TextBox1.ForeColor = &H80000008
Else
TextBox1.BackColor = vbRed
TextBox1.ForeColor = vbWhite
End If

Erase Veri
Erase Liste


End Sub

Private Sub UserForm_Initialize()
Set S1 = Sheets("KAYİT")
With Me.lstpersonel
.ColumnCount = 17
lstpersonel.ColumnWidths = "50;150;50;50;230;50;50;50;50;50;50;50;50;50;50;50"

.List = S1.Range("A2:Q" & S1.Cells(S1.Rows.Count, 1).End(3).Row).Value
.AddItem , 0
For X = 1 To 17
.List(0, X - 1) = S1.Cells(1, X).Value
Next
.ListIndex = 0
End With
End Sub

Dim ws As Worksheet
Dim comboSelection As String
Dim comboSelection1 As String
Dim comboSelection2 As String
Dim textbox7Value As String
Dim textbox6Value As String
Dim textbox1002Value As String
Dim textbox1003Value As String
Dim textbox1004Value As String
Dim textbox1005Value As String
Dim textbox1006Value As String
Dim textbox1007Value As String
Dim textbox1008Value As String
Dim textbox1009Value As String
Dim textbox1010Value As String
Dim textbox1011Value As String
Dim textbox1012Value As String
Dim textbox1013Value As String
Dim textbox1014Value As String
Dim textbox1018Value As String
Dim textbox1015Value As String
Dim textbox1016Value As String
Dim textbox1017Value As String

karar = MsgBox("Müşteri Kaydı Silinecek Onaylıyormusunuz?", vbYesNo, "Uyarı!")
If karar = vbYes Then


Set ws = ThisWorkbook.Sheets("KAYİT")


TextBox7.Value = ""
TextBox6.Value = ""
TextBox1002.Value = ""
TextBox1003.Value = ""
TextBox1004.Value = ""
TextBox1005.Value = ""
TextBox1006.Value = ""
TextBox1007.Value = ""
TextBox1008.Value = ""
TextBox1009.Value = ""
TextBox1010.Value = ""
TextBox1011.Value = ""
TextBox1012.Value = ""
TextBox1013.Value = ""
TextBox1014.Value = ""
TextBox1018.Value = ""
TextBox1015.Value = ""
TextBox1016.Value = ""
TextBox1017.Value = ""
ComboBox3.Value = ""
ComboBox4.Value = ""
ComboBox5.Value = ""
ComboBox6.Value = ""
ComboBox7.Value = ""
Selection.EntireRow.Delete
Else
MsgBox ("Silme İşlemi İptal Edildi.!"), vbInformation
End If
 

KuTuKa

Altın Üye
Katılım
10 Mart 2005
Mesajlar
731
Excel Vers. ve Dili
Microsoft Office LTSC Pr. Pl 2021 - 64 bit Türkçe
Altın Üyelik Bitiş Tarihi
19-03-2029
Merhaba

anladığım kadarı ile ben bir düzeltme yaptım.

Sorunun nedeni, seçili satırı değil, en üst satırı siliyor olması. Bunun nedeni Selection.EntireRow.Delete kullanmanızdır. Ancak Selection genellikle Excel'deki aktif hücreyi referans alır, ListBox içindeki seçili veriyi değil.




Private Sub btnSil_Click()
Dim ws As Worksheet
Dim seciliSatir As Long
Dim aramaSonucu As Range
Dim karar As Integer

' Çalışma sayfasını tanımla
Set ws = ThisWorkbook.Sheets("KAYİT")

' Seçili satır yoksa uyarı ver
If lstpersonel.ListIndex = -1 Then
MsgBox "Lütfen silmek için bir satır seçin!", vbExclamation, "Uyarı"
Exit Sub
End If

' Kullanıcıdan onay al
karar = MsgBox("Seçili müşteri kaydı silinecek, onaylıyor musunuz?", vbYesNo, "Uyarı!")
If karar = vbNo Then Exit Sub

' ListBox'tan seçilen satırın ilk sütundaki değeri (ID veya isim) al
Dim arananDeger As String
arananDeger = lstpersonel.List(lstpersonel.ListIndex, 0) ' 0. sütun ID veya isim olmalı

' KAYİT sayfasında ilgili satırı bul
Set aramaSonucu = ws.Range("A:A").Find(What:=arananDeger, LookAt:=xlWhole)

' Eğer değer bulunduysa satırı sil
If Not aramaSonucu Is Nothing Then
seciliSatir = aramaSonucu.Row
ws.Rows(seciliSatir).Delete
MsgBox "Kayıt başarıyla silindi.", vbInformation, "Bilgi"

' ListBox'ı güncelle
Call ListeyiGuncelle
Else
MsgBox "Kayıt bulunamadı!", vbExclamation, "Hata"
End If
End Sub
 
Üst