Pencarian tampil di listBox sesuai database di Excel dengan VBA
Dengan menggunakan userform..
Private Sub cmdcari_Click()
Listcari.Clear
Dim RowNum As Long
Me.Listcari.Clear
'for header
Me.Listcari.AddItem "KODE"
Me.Listcari.List(Listcari.ListCount - 1, 1) = "NAMA MATERIAL"
Me.Listcari.List(Listcari.ListCount - 1, 2) = "STD PLT 1"
Me.Listcari.List(Listcari.ListCount - 1, 3) = "STD PLT 2"
Me.Listcari.ColumnWidths = 50 & ";" & 200 & ";" & 50 & ";" & 50
Me.Listcari.Selected(0) = True
RowNum = 1
Do Until Sheets("MASTERDATA").Cells(RowNum, 2).Value = ""
If InStr(1, Sheets("MASTERDATA").Cells(RowNum, 2).Value, TSBARCODE.Value, vbTextCompare) > 0 Then
On erro GoTo next1
Listcari.AddItem Sheets("MASTERDATA").Cells(RowNum, 1).Value
Listcari.List(Listcari.ListCount - 1, 1) = Sheets("MASTERDATA").Cells(RowNum, 2).Value
Listcari.List(Listcari.ListCount - 1, 2) = Sheets("MASTERDATA").Cells(RowNum, 3).Value
Listcari.List(Listcari.ListCount - 1, 3) = Sheets("MASTERDATA").Cells(RowNum, 4).Value
Listcari.List(Listcari.ListCount - 1, 4) = Sheets("MASTERDATA").Cells(RowNum, 5).Value
End If
next1:
RowNum = RowNum + 1
Loop
Dim RowNum As Long
Me.Listcari.Clear
'for header
Me.Listcari.AddItem "KODE"
Me.Listcari.List(Listcari.ListCount - 1, 1) = "NAMA MATERIAL"
Me.Listcari.List(Listcari.ListCount - 1, 2) = "STD PLT 1"
Me.Listcari.List(Listcari.ListCount - 1, 3) = "STD PLT 2"
Me.Listcari.ColumnWidths = 50 & ";" & 200 & ";" & 50 & ";" & 50
Me.Listcari.Selected(0) = True
RowNum = 1
Do Until Sheets("MASTERDATA").Cells(RowNum, 2).Value = ""
If InStr(1, Sheets("MASTERDATA").Cells(RowNum, 2).Value, TSBARCODE.Value, vbTextCompare) > 0 Then
On erro GoTo next1
Listcari.AddItem Sheets("MASTERDATA").Cells(RowNum, 1).Value
Listcari.List(Listcari.ListCount - 1, 1) = Sheets("MASTERDATA").Cells(RowNum, 2).Value
Listcari.List(Listcari.ListCount - 1, 2) = Sheets("MASTERDATA").Cells(RowNum, 3).Value
Listcari.List(Listcari.ListCount - 1, 3) = Sheets("MASTERDATA").Cells(RowNum, 4).Value
Listcari.List(Listcari.ListCount - 1, 4) = Sheets("MASTERDATA").Cells(RowNum, 5).Value
End If
next1:
RowNum = RowNum + 1
Loop
End Sub ()
Terima kasih
ReplyDeleteini yang di cari²
ReplyDeletekq ga bisa ya, muncul sintax error
ReplyDelete