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:
I hope that seniors will be willing to provide a solution to this problem.
Thank you for your help and guidance.
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.