Not Like operator

belilibom

New Member
Joined
Jul 4, 2023
Messages
9
Office Version
  1. 2010
I wrote a code using the not like operator to display a message if the data in the listbox table does not contain the year searched for according to the combobox. However, an error occurs by still displaying the message box even though the year in the combobox is replaced with a different year, and cannot display data in the listbox even though the data is in the listbox.
The code is as follows:
VBA Code:
Private Sub Combo_CariTahun_Change()
Dim i As Long
Set Aktif_Sheet = Worksheets("Arsif-Lama")
Baris_Terakhir = Aktif_Sheet.Cells(Rows.Count, 1).End(xlUp).Row
With ListBox_ArsifLama
    .Clear
    .ColumnCount = 11
    .List = Aktif_Sheet.Range("A1", "FD1").Value
    .RemoveItem 0
    For i = 3 To Baris_Terakhir
        If Not Left(Aktif_Sheet.Cells(i, 3).Value, 4) Like "*" & Combo_CariTahun & "*" Then
            MsgBox "DATA TIDAK DITEMUKAN !" & vbNewLine & vbNewLine & "Tahun Akta Wakaf yang anda cari tidak ditemukan." , vbExclamation + vbOKOnly, "Rumah Wakaf"
            Exit Sub
        Else
        'If Left(Aktif_Sheet.Cells(i, 3).Value, 4) Like "*" & Combo_CariTahun & "*" Then
            .AddItem
            .List(.ListCount - 1, 0) = Sheet17.Cells(i, 1)
            .List(.ListCount - 1, 1) = Sheet17.Cells(i, 2)
            .List(.ListCount - 1, 2) = Sheet17.Cells(i, 3)
            .ColumnWidths = "25,36,28"
        End If
        End If
    Next i
End With
End Sub

I hope that seniors will be willing to provide a solution to this problem.
Thank you for your help and guidance.
 

Excel Facts

Difference between two dates
Secret function! Use =DATEDIF(A2,B2,"Y")&" years"&=DATEDIF(A2,B2,"YM")&" months"&=DATEDIF(A2,B2,"MD")&" days"
try with brackets:
VBA Code:
If Not (Left(Aktif_Sheet.Cells(i, 3).Value, 4) Like "*" & Combo_CariTahun & "*") Then
I would also suggest to step through the code and debug - for example put a breakpoint on this same line and confirm the values you try to compare are what you expect.
 
Upvote 0
Your code loops over a table column with years. Once it finds a year, different from the year in the combobox, it ends the code.
That is not what your are trying to do, accoriding to your description.

Or should all years in the table be the same as the year in the combobox?
 
Upvote 0
Your code loops over a table column with years. Once it finds a year, different from the year in the combobox, it ends the code.
That is not what your are trying to do, accoriding to your description.

Or should all years in the table be the same as the year in the combobox?
Yes, the table should display the same years as in the combobox.
 
Upvote 0
Your code loops over a table column with years. Once it finds a year, different from the year in the combobox, it ends the code.
That is not what your are trying to do, accoriding to your description.

Or should all years in the table be the same as the year in the combobox?
Yes, the table should display the same years as in the combobox.
 
Upvote 0
try with brackets:
VBA Code:
If Not (Left(Aktif_Sheet.Cells(i, 3).Value, 4) Like "*" & Combo_CariTahun & "*") Then
I would also suggest to step through the code and debug - for example put a breakpoint on this same line and confirm the values you try to compare are what you expect.
okay i will try it
 
Upvote 0
try with brackets:
VBA Code:
If Not (Left(Aktif_Sheet.Cells(i, 3).Value, 4) Like "*" & Combo_CariTahun & "*") Then
I would also suggest to step through the code and debug - for example put a breakpoint on this same line and confirm the values you try to compare are what you expect.
I've tried it, and the results are still the same as before.
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,175
Members
453,021
Latest member
Justyna P

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top