listbox içinde geçen kelime ye göre buton pasif yapmak

netvolxxx

Altın Üye
Katılım
29 Ağustos 2023
Mesajlar
211
Excel Vers. ve Dili
2013 Türkçe
Altın Üyelik Bitiş Tarihi
15-04-2027
merhaba arkadaşlar şöyle bir işlemi nasıl yapabilirim bi türlü yapamadım pes etmek üzereyim...

userform üzerinde listbox ta içine gelen bir yazı geçiyorsa buton1 pasif olcak . o kelime geçmiyorsa aktif olcak buton
(listbox3 alanında denemelerx kelime geçiyorsa buton1 pasif olcak.)

TextBox2.Value = ListBox3.List(ListBox3.ListIndex, 7)

listbox3 alanında dblclick yaptığında textbox2 alanına denk geliyor

textbox 2 alanında buton la ilgili başka bir kod var örnek ikisini beraber çalıştıramadım.

If TextBox2 <> "denemelerx" Then
CommandButton2.Visible = True
Else
CommandButton2.Visible = False
End If

f TextBox2 <> "denemelerx" Then
CommandButton1.Visible = True
Else
CommandButton1.Visible = False
End If


UserForm_Initialize
CommandButton1.Visible = False
CommandButton2.Visible = False

bu şekilde yazdığımda olmadı textbox2 alanı boş ise yada başka bir şey yazıyorsa butonlar aktif oluyor benin isteğim listbox3 alanında denemelerx kelime geçiyorsa buton1 pasif olcak.

nasıl yapabilirim bunu.
 

muhasebeciyiz

Altın Üye
Katılım
10 Şubat 2006
Mesajlar
1,214
Excel Vers. ve Dili
Office 2016
64 Bit
Altın Üyelik Bitiş Tarihi
21-12-2027
Bunu TextBox2’ye bakarak değil, doğrudan ListBox3’te seçilen satırın 8. sütununa (index 7) bakarak yapman daha sağlıklı. Çünkü TextBox2 bazen boş kalabiliyor / başka event’ler karışabiliyor.

Aşağıdaki gibi tek bir prosedür yazıp hem ListBox3_DblClick içinde hem de ListBox3_Change/Click içinde çağırırsan, iki kod birbiriyle çakışmaz.

“ListBox3’ün (seçili satır, sütun 7) içinde denemelerx geçiyorsa CommandButton1 pasif (görünmesin), geçmiyorsa aktif (görünsün).”

Kod:
Private Sub UpdateButtonsFromListBox()
    Dim s As String
    
    If ListBox3.ListIndex < 0 Then
        CommandButton1.Visible = False
        CommandButton2.Visible = False
        Exit Sub
    End If
    
    s = CStr(ListBox3.List(ListBox3.ListIndex, 7))
  
    TextBox2.Value = s
    
    If InStr(1, s, "denemelerx", vbTextCompare) > 0 Then
        CommandButton1.Visible = False
    Else
        CommandButton1.Visible = True
    End If
    
    CommandButton2.Visible = True
End Sub
ListBox3’te çift tıklayınca çalıştır

Kod:
Private Sub ListBox3_DblClick(ByVal Cancel As MSForms.ReturnBoolean)
    UpdateButtonsFromListBox
End Sub
Seçim değişince de anında güncellensin (önerilir)

Private Sub ListBox3_Change()
UpdateButtonsFromListBox
End Sub

(İstersen ListBox3_Click da olur.)

İnitalize

Private Sub UserForm_Initialize()
CommandButton1.Visible = False
CommandButton2.Visible = False
End Sub
 

netvolxxx

Altın Üye
Katılım
29 Ağustos 2023
Mesajlar
211
Excel Vers. ve Dili
2013 Türkçe
Altın Üyelik Bitiş Tarihi
15-04-2027
Bunu TextBox2’ye bakarak değil, doğrudan ListBox3’te seçilen satırın 8. sütununa (index 7) bakarak yapman daha sağlıklı. Çünkü TextBox2 bazen boş kalabiliyor / başka event’ler karışabiliyor.

Aşağıdaki gibi tek bir prosedür yazıp hem ListBox3_DblClick içinde hem de ListBox3_Change/Click içinde çağırırsan, iki kod birbiriyle çakışmaz.

“ListBox3’ün (seçili satır, sütun 7) içinde denemelerx geçiyorsa CommandButton1 pasif (görünmesin), geçmiyorsa aktif (görünsün).”

Kod:
Private Sub UpdateButtonsFromListBox()
    Dim s As String
  
    If ListBox3.ListIndex < 0 Then
        CommandButton1.Visible = False
        CommandButton2.Visible = False
        Exit Sub
    End If
  
    s = CStr(ListBox3.List(ListBox3.ListIndex, 7))

    TextBox2.Value = s
  
    If InStr(1, s, "denemelerx", vbTextCompare) > 0 Then
        CommandButton1.Visible = False
    Else
        CommandButton1.Visible = True
    End If
  
    CommandButton2.Visible = True
End Sub
ListBox3’te çift tıklayınca çalıştır

Kod:
Private Sub ListBox3_DblClick(ByVal Cancel As MSForms.ReturnBoolean)
    UpdateButtonsFromListBox
End Sub
Seçim değişince de anında güncellensin (önerilir)

Private Sub ListBox3_Change()
UpdateButtonsFromListBox
End Sub

(İstersen ListBox3_Click da olur.)

İnitalize

Private Sub UserForm_Initialize()
CommandButton1.Visible = False
CommandButton2.Visible = False
End Sub
üstad merhaba denedim fakat hata aldım ya Private Sub UpdateButtonsFromListBox() module olarak ekledim yazdım çalıştırdım fakat listbox tıkladığımda yada çift tıkladığımda UpdateButtonsFromListBox buraya gidiyor kalıyor hata bunu bulamıyor farklı userform var makroda bunuda belirtmek lazım..

şurda hata veriyodu If ListBox3.ListIndex < 0 Then
böyle yaptım ama
If ListBox3.ListIndex <> 0 Then
 

muhasebeciyiz

Altın Üye
Katılım
10 Şubat 2006
Mesajlar
1,214
Excel Vers. ve Dili
Office 2016
64 Bit
Altın Üyelik Bitiş Tarihi
21-12-2027
Soldan UserForm hangisiyse (ör: UserForm1) ona çift tıkla
Açılan UserForm code penceresine şunu yapıştır:


Kod:
Private Sub UpdateButtonsFromListBox()
    Dim s As String
    
    If Me.ListBox3.ListIndex = -1 Then
        Me.CommandButton1.Visible = False
        Exit Sub
    End If
    
    s = CStr(Me.ListBox3.List(Me.ListBox3.ListIndex, 7))
    Me.TextBox2.Value = s
    
    If InStr(1, s, "denemelerx", vbTextCompare) > 0 Then
        Me.CommandButton1.Visible = False
    Else
        Me.CommandButton1.Visible = True
    End If
End Sub
ListBox event’lerine bunu ekle (aynı UserForm içinde)

Kod:
Private Sub ListBox3_Click()
    UpdateButtonsFromListBox
End Sub

Private Sub ListBox3_DblClick(ByVal Cancel As MSForms.ReturnBoolean)
    UpdateButtonsFromListBox
End Sub
İnitailize
Private Sub UserForm_Initialize()
Me.CommandButton1.Visible = False
End Sub

ListBox3 hangi UserForm’da? Adı tam olarak ne (ör: UserForm_ABC)?
Button1’in adı gerçekten CommandButton1 mi, yoksa sende CommandButton1 başka formda mı?
 

netvolxxx

Altın Üye
Katılım
29 Ağustos 2023
Mesajlar
211
Excel Vers. ve Dili
2013 Türkçe
Altın Üyelik Bitiş Tarihi
15-04-2027
Şurası tam tersi olcak aslında :“ListBox3’ün (seçili satır, sütun 7) içinde denemelerx geçiyorsa CommandButton1 pasif (görünmesin), geçmiyorsa aktif (görünsün).

call UpdateButtonsFromListBox yazınca hata almadım ama denemelerx geçiyorsa command1 pasif olcak geçmiyorsa aktif olcak.. burası kaldı bi tek.
 

netvolxxx

Altın Üye
Katılım
29 Ağustos 2023
Mesajlar
211
Excel Vers. ve Dili
2013 Türkçe
Altın Üyelik Bitiş Tarihi
15-04-2027
Soldan UserForm hangisiyse (ör: UserForm1) ona çift tıkla
Açılan UserForm code penceresine şunu yapıştır:


Kod:
Private Sub UpdateButtonsFromListBox()
    Dim s As String
  
    If Me.ListBox3.ListIndex = -1 Then
        Me.CommandButton1.Visible = False
        Exit Sub
    End If
  
    s = CStr(Me.ListBox3.List(Me.ListBox3.ListIndex, 7))
    Me.TextBox2.Value = s
  
    If InStr(1, s, "denemelerx", vbTextCompare) > 0 Then
        Me.CommandButton1.Visible = False
    Else
        Me.CommandButton1.Visible = True
    End If
End Sub
ListBox event’lerine bunu ekle (aynı UserForm içinde)

Kod:
Private Sub ListBox3_Click()
    UpdateButtonsFromListBox
End Sub

Private Sub ListBox3_DblClick(ByVal Cancel As MSForms.ReturnBoolean)
    UpdateButtonsFromListBox
End Sub
İnitailize
Private Sub UserForm_Initialize()
Me.CommandButton1.Visible = False
End Sub

ListBox3 hangi UserForm’da? Adı tam olarak ne (ör: UserForm_ABC)?
Button1’in adı gerçekten CommandButton1 mi, yoksa sende CommandButton1 başka formda mı?
bu çalışıyor hocam yanlız tam tersi olcak uygulama denemelerx geçiyorsa pasif olcak geçmiyorsa aktif olcak.
 

muhasebeciyiz

Altın Üye
Katılım
10 Şubat 2006
Mesajlar
1,214
Excel Vers. ve Dili
Office 2016
64 Bit
Altın Üyelik Bitiş Tarihi
21-12-2027
Kod:
Private Sub UpdateButtonsFromListBox()
    Dim s As String
   
    If Me.ListBox3.ListIndex = -1 Then
        Me.CommandButton1.Visible = False
        Exit Sub
    End If
   
    s = CStr(Me.ListBox3.List(Me.ListBox3.ListIndex, 7))
    Me.TextBox2.Value = s
   
    If InStr(1, s, "denemelerx", vbTextCompare) > 0 Then
        Me.CommandButton1.Visible = False
    Else
        Me.CommandButton1.Visible = True
    End If
End Sub

ListBox event’leri (aynı formda)

Private Sub ListBox3_Click()
UpdateButtonsFromListBox
End Sub

Private Sub ListBox3_DblClick(ByVal Cancel As MSForms.ReturnBoolean)
UpdateButtonsFromListBox
End Sub


Private Sub UserForm_Initialize()
Me.CommandButton1.Visible = False
End Sub

Eğer “Visible” değil de gerçekten pasif (disable) olsun dersen:

Me.CommandButton1.Enabled = False ' pasif
Me.CommandButton1.Enabled = True ' aktif
 

netvolxxx

Altın Üye
Katılım
29 Ağustos 2023
Mesajlar
211
Excel Vers. ve Dili
2013 Türkçe
Altın Üyelik Bitiş Tarihi
15-04-2027
Kod:
Private Sub UpdateButtonsFromListBox()
    Dim s As String
  
    If Me.ListBox3.ListIndex = -1 Then
        Me.CommandButton1.Visible = False
        Exit Sub
    End If
  
    s = CStr(Me.ListBox3.List(Me.ListBox3.ListIndex, 7))
    Me.TextBox2.Value = s
  
    If InStr(1, s, "denemelerx", vbTextCompare) > 0 Then
        Me.CommandButton1.Visible = False
    Else
        Me.CommandButton1.Visible = True
    End If
End Sub

ListBox event’leri (aynı formda)

Private Sub ListBox3_Click()
UpdateButtonsFromListBox
End Sub

Private Sub ListBox3_DblClick(ByVal Cancel As MSForms.ReturnBoolean)
UpdateButtonsFromListBox
End Sub


Private Sub UserForm_Initialize()
Me.CommandButton1.Visible = False
End Sub

Eğer “Visible” değil de gerçekten pasif (disable) olsun dersen:

Me.CommandButton1.Enabled = False ' pasif
Me.CommandButton1.Enabled = True ' aktif
ustad bu kod denemelerx yazıyorsa tıkladığımda pasif yapıyor boş ise aktif yapıyor tam tersini nasıl yapıcam kod tarafında false true yerlerini değiştirdim olmuyor...
 
Üst