Soru Listbox da secilen veriyi Textbox a aktardiktan sonra veri güncelleme sorunu.

Katılım
20 Haziran 2011
Mesajlar
12
Excel Vers. ve Dili
Microsoft 365 Deutsch
Arkadaslar Merhaba,
Listbox daki veriyi secince Textboxa aktarimini yapiyorum, fakat degisiklik yapamiyorum,aslinda sebebinin biliyorum ama cözüm bulamadim, listbox da secilen verinin ayni zamanda excel sayfasinda da secilmesi yani bulunmasi gerekiyor ki, textbox üzerinde yaptigim degisikliklik gerceklessin,
asagidaki kodlar ile listbox daki veriye cift tiklayinca textbox a getiriyorum

Tarih.Value = ListBox1.List(ListBox1.ListIndex, 0)
Odanumarasi.Value = ListBox1.List(ListBox1.ListIndex, 1)
Sperrung.Value = ListBox1.List(ListBox1.ListIndex, 2)
Grund.Value = ListBox1.List(ListBox1.ListIndex, 3)
Sonstiges.Value = ListBox1.List(ListBox1.ListIndex, 4)

fakat bu verilerin excel sayfasindaki yerini bulmasi gerekiyor. yani listbox oda numarasi 20 yi secince , oda numarasi 20 ye ait bilgiler textbox da görünüyor, fakat degisiklik yapmak istedigim zaman excel sayfasinda oda numarasi 20 nin kayitli oldugu satira gitmesi icin gereken kodlar veya izlenmesi gereken yolu bulamadim. Yardimlariniz icin simdiden tesekkür ediyorum..
 
Katılım
11 Temmuz 2024
Mesajlar
42
Excel Vers. ve Dili
Excel 2021 Türkçe
Merhaba hocam şu şekilde deneyip sonucu paylaşabilir misiniz;


Kod:
Sub ListBoxDoldur()
    Dim ws As Worksheet
    Dim sonSatir As Long
    Dim i As Long

    Set ws = Worksheets("SayfaAdi") ' Çalışma sayfanızın adını yazın

    sonSatir = ws.Cells(ws.Rows.Count, "A").End(xlUp).Row

    ListBox1.Clear

    ListBox1.ColumnCount = 6
    ListBox1.ColumnWidths = "80;80;80;80;80;0"

    For i = 2 To sonSatir
        With ListBox1
            .AddItem ws.Cells(i, "A").Value
            .List(.ListCount - 1, 1) = ws.Cells(i, "B").Value
            .List(.ListCount - 1, 2) = ws.Cells(i, "C").Value
            .List(.ListCount - 1, 3) = ws.Cells(i, "D").Value
            .List(.ListCount - 1, 4) = ws.Cells(i, "E").Value
            .List(.ListCount - 1, 5) = i
        End With
    Next i
End Sub

Private Sub ListBox1_Click()
    If ListBox1.ListIndex = -1 Then Exit Sub

    Dim secilenSatir As Long

    secilenSatir = CLng(ListBox1.List(ListBox1.ListIndex, 5))

    Tarih.Value = ListBox1.List(ListBox1.ListIndex, 0)
    Odanumarasi.Value = ListBox1.List(ListBox1.ListIndex, 1)
    Sperrung.Value = ListBox1.List(ListBox1.ListIndex, 2)
    Grund.Value = ListBox1.List(ListBox1.ListIndex, 3)
    Sonstiges.Value = ListBox1.List(ListBox1.ListIndex, 4)
    
    Me.Tag = secilenSatir
End Sub


Private Sub GuncelleButton_Click()
    If Me.Tag = "" Then
        MsgBox "Lütfen güncellemek istediğiniz kaydı seçin.", vbExclamation
        Exit Sub
    End If

    Dim ws As Worksheet
    Dim satirNo As Long

    Set ws = Worksheets("SayfaAdi") ' Çalışma sayfanızın adını yazın

    satirNo = CLng(Me.Tag)

    With ws
        .Cells(satirNo, "A").Value = Tarih.Value
        .Cells(satirNo, "B").Value = Odanumarasi.Value
        .Cells(satirNo, "C").Value = Sperrung.Value
        .Cells(satirNo, "D").Value = Grund.Value
        .Cells(satirNo, "E").Value = Sonstiges.Value
    End With

    MsgBox "Kayıt başarıyla güncellendi.", vbInformation

    Call ListBoxDoldur

    Tarih.Value = ""
    Odanumarasi.Value = ""
    Sperrung.Value = ""
    Grund.Value = ""
    Sonstiges.Value = ""

    ListBox1.ListIndex = -1


    Me.Tag = ""
End Sub
 
Katılım
20 Haziran 2011
Mesajlar
12
Excel Vers. ve Dili
Microsoft 365 Deutsch
Merhaba hocam şu şekilde deneyip sonucu paylaşabilir misiniz;


Kod:
Sub ListBoxDoldur()
    Dim ws As Worksheet
    Dim sonSatir As Long
    Dim i As Long

    Set ws = Worksheets("SayfaAdi") ' Çalışma sayfanızın adını yazın

    sonSatir = ws.Cells(ws.Rows.Count, "A").End(xlUp).Row

    ListBox1.Clear

    ListBox1.ColumnCount = 6
    ListBox1.ColumnWidths = "80;80;80;80;80;0"

    For i = 2 To sonSatir
        With ListBox1
            .AddItem ws.Cells(i, "A").Value
            .List(.ListCount - 1, 1) = ws.Cells(i, "B").Value
            .List(.ListCount - 1, 2) = ws.Cells(i, "C").Value
            .List(.ListCount - 1, 3) = ws.Cells(i, "D").Value
            .List(.ListCount - 1, 4) = ws.Cells(i, "E").Value
            .List(.ListCount - 1, 5) = i
        End With
    Next i
End Sub

Private Sub ListBox1_Click()
    If ListBox1.ListIndex = -1 Then Exit Sub

    Dim secilenSatir As Long

    secilenSatir = CLng(ListBox1.List(ListBox1.ListIndex, 5))

    Tarih.Value = ListBox1.List(ListBox1.ListIndex, 0)
    Odanumarasi.Value = ListBox1.List(ListBox1.ListIndex, 1)
    Sperrung.Value = ListBox1.List(ListBox1.ListIndex, 2)
    Grund.Value = ListBox1.List(ListBox1.ListIndex, 3)
    Sonstiges.Value = ListBox1.List(ListBox1.ListIndex, 4)
   
    Me.Tag = secilenSatir
End Sub


Private Sub GuncelleButton_Click()
    If Me.Tag = "" Then
        MsgBox "Lütfen güncellemek istediğiniz kaydı seçin.", vbExclamation
        Exit Sub
    End If

    Dim ws As Worksheet
    Dim satirNo As Long

    Set ws = Worksheets("SayfaAdi") ' Çalışma sayfanızın adını yazın

    satirNo = CLng(Me.Tag)

    With ws
        .Cells(satirNo, "A").Value = Tarih.Value
        .Cells(satirNo, "B").Value = Odanumarasi.Value
        .Cells(satirNo, "C").Value = Sperrung.Value
        .Cells(satirNo, "D").Value = Grund.Value
        .Cells(satirNo, "E").Value = Sonstiges.Value
    End With

    MsgBox "Kayıt başarıyla güncellendi.", vbInformation

    Call ListBoxDoldur

    Tarih.Value = ""
    Odanumarasi.Value = ""
    Sperrung.Value = ""
    Grund.Value = ""
    Sonstiges.Value = ""

    ListBox1.ListIndex = -1


    Me.Tag = ""
End Sub
hocam öncelikle zaman ayirip cevap verdiginiz icin tesekkür ederim.

maalesef verdiginiz kodlar ile sonuc alamadim herhangi hata da vermiyor, excel sayfasinda secili oda numarasini bulmuyor.
dedigim gibi listboxta görünen veriyi secince textbox a veriler geliyor, fakat o veri excel sayfasindaki kayit yerini bulmadigi icin güncelleme kodlari ise yaramiyor. yani listboxdaki veriye tiklayinca, o verinin kayitli oldugu sayfada ki satirina gitmesi gerekiyor ki , degisikligi yapabileyim
 
Üst