Makro ile filtre kaldırma

Katılım
10 Nisan 2014
Mesajlar
113
Excel Vers. ve Dili
2013 ingilizce
Altın Üyelik Bitiş Tarihi
08/11/2017
Arkadaşlar merhaba,

Verileri excel'e yazmak için userform kullanılıyorum. Ve bu form aşağıdaki kod ile çalışmakta. Yapmak istediğim "Ödemeler 2017" sayfasına verileri yazmadan bu sayfadaki filtrelerin hepsini kaldırması sonrasında son satıra yazması.Aksi taktirde Ödemeler 2017 sayfasında filtre olduğu zaman mevcut kayıtlı verilerin üzerine yazıyor. Bu kodu nasıl düzenleyebilirim yardımcı olursanız sevinirim.

Kod:
Private Sub CommandButton1_Click()
If TextBox7.Value <> "" And TextBox2.Value <> "" And TextBox3 <> "" And TextBox4 <> "" And TextBox5 <> "" And TextBox6 <> "" And TextBox8 <> "" Then


Set s1 = Sheets("CH1-1 transfer")
Set s2 = Sheets("Ödemeler 2017")


    b = ActiveCell.Row
    
    
   
    s1.Cells(b, "C").Value = TextBox2.Value
    s1.Cells(b, "F").Value = TextBox4.Value
    s1.Cells(b, "H").Value = ComboBox3.Value
    s1.Cells(b, "L").Value = CDbl(TextBox7.Value)
    s1.Cells(b, "M").Value = TextBox8.Value
    s1.Cells(b, "D").Value = "A+"
    If s1.Cells(b, "k").Value - TextBox7.Value >= 0 And s1.Cells(b, "k").Value <> "" Then
    s1.Cells(b, "k").Value = s1.Cells(b, "k").Value - TextBox7.Value
    Else
    s1.Cells(b, "k").Value = ""
    End If
        

    k = s2.Range("J65536").End(xlUp).Row
    X = s2.Range("J65536").End(xlUp).Row + 1
    'y = s2.Cells(k, 1).Value
    s2.Cells(X, 1).Value = X + 1
    
    
 
    
    s2.Cells(X, "B").Value = ComboBox2.Value
    s2.Cells(X, "C").Value = ComboBox1.Value
    s2.Cells(X, "D").Value = TextBox3.Value
    s2.Cells(X, "E").Value = TextBox2.Value
    s2.Cells(X, "F").Value = TextBox5.Value
    s2.Cells(X, "G").Value = TextBox4.Value
    s2.Cells(X, "H").Value = ComboBox3.Value
    s2.Cells(X, "L").Value = CDbl(TextBox7.Value)
    s2.Cells(X, "J").Value = TextBox8.Value
    s2.Cells(X, "K").Value = TextBox6.Value
    
    
    
    
    
    If MsgBox("ÖDEME TALEP FORMU OLUSTURMAK iSTERMiSiNiZ ?", vbYesNo, "UYARI!") = vbNo Then
   
    If CloseMode = 0 Then
    Cancel = True
    End If
    Unload UserForm1
    Else
    
Application.ScreenUpdating = False
yol = ThisWorkbook.Path & "\" & "Ödeme Talebi.xlsx"
Workbooks.Open (yol)
Sheets("Sheet1").Select

Cells(14, "f") = TextBox3
Cells(14, "h") = TextBox2
Cells(12, "f") = TextBox4
Cells(15, "h") = TextBox8
Cells(20, "f") = TextBox5
Cells(23, "c") = TextBox7 * 1.18
Cells(15, "b") = ComboBox3


Application.ScreenUpdating = True
    MsgBox "KAYIT TAMAMLANDI ÖDEME FORMU OLUSTURULDU", , "BiLGi"
    
     If CloseMode = 0 Then
    Cancel = True
    End If
    Unload UserForm1
   
  End If
    
    
    Else
    
    MsgBox "BOS ALANLAR VAR !!", , "BiLGi"
    
    
End If

End Sub
 

Korhan Ayhan

Administrator
Yönetici
Admin
Katılım
15 Mart 2005
Mesajlar
43,168
Excel Vers. ve Dili
Microsoft 365 Tr-En 64 Bit
Aşağıdaki kod satırlarını SET ifadelerinden sonrasına ekleyip deneyiniz.

Kod:
On Error Resume Next
s2.ShowAllData
On Error Goto 0
 

Murat OSMA

Altın Üye
Altın Üye
Katılım
23 Mayıs 2011
Mesajlar
5,508
Excel Vers. ve Dili
Microsoft 365 TR-EN
Altın Üyelik Bitiş Tarihi
31-12-2028
Sayfada filtreleme olmadığında, filtreyi kaldırmak istediğimizde hata alırız.
Eğer sayfada filtre varsa o filtreyi kaldır demek daha mantıklı bir hareket olacaktır.


Kod:
[SIZE="2"]    If s2.FilterMode = True Then
        s2.ShowAllData
    End If[/SIZE]
 
Katılım
10 Nisan 2014
Mesajlar
113
Excel Vers. ve Dili
2013 ingilizce
Altın Üyelik Bitiş Tarihi
08/11/2017
Seyahatte olduğum için geç cevap yazabildim kusura bakmayın lütfen Çok teşekkür ederim yardımızın için
 

Orion1

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

Ofis-2010-TR 32 Bit
Autofilter için aşağıdaki kodu kullanabilirsiniz.:cool:

Kod:
If s2.AutoFilterMode = True Then
    s2.AutoFilterMode = False
End If
 
Üst