-
here is the full code, i keep getting a handful of compile errors like end if without block if, loop without do ect. ive managed to get those errors out however now the code is not returning any data to the list box and ever search returns the msgbox "not found in database", im fairly new to the coding language and i think im just making it worse by trying to research and fix on my own, i feel like there is a couple small details that are being missed. any help is much appreciated!
Private Sub parts2_Click()
Dim i As Long, lastrow As Long
lastrow = Sheets("database").Range("a" & Rows.Count).End(xlUp).row
For i = 1 To lastrow
If Sheets("database").Cells(i, "A").Value = (Me.Partnumber2.Value) Or _
Sheets("database").Cells(i, "A").Value = (Me.Partnumber2.Value) Then
Me.partsearch2 = Sheets("database").Cells(i, "a").Value
Me.ComboBox5 = Sheets("database").Cells(i, "f").Value
Me.StorLoc2 = Sheets("database").Cells(i, "c").Value
Me.BinLoc2 = Sheets("database").Cells(i, "d").Value
Me.QTY2 = Sheets("database").Cells(i, "e").Value
Me.ComboBox6 = Sheets("database").Cells(i, "h").Value
Me.Desc2 = Sheets("database").Cells(i, "B").Value
Me.rownumber2 = Sheets("database").Cells(i, "K").Value
End If
Next
Dim rngToSearch As Range
Dim rngToFind As Range
Dim valToFind As Variant
Dim arrClearList()
Dim row As Integer
ListBox2.Clear
valToFind = Me.partsearch2.Value 'ComboBox name
With Worksheets("database")
Set rngToSearch = .Columns("A")
End With
Set rngToFind = rngToSearch.Find(What:=valToFind, _
LookIn:=xlFormulas, _
LookAt:=xlWhole, _
SearchOrder:=xlByRows, _
SearchDirection:=xlNext, _
MatchCase:=False)
If Not rngToFind Is Nothing And partsearch2.Value = "" Then
GoTo found
Else
MsgBox ("Not found in Database")
End If
Exit Sub
found:
Do
DoEvents
If Sheets("database").Cells(i, "A").Value = (Me.Partnumber2.Value) Then
ListBox2.AddItem
With ListBox2
.List(.ListCount - 1, 0) = rngToFind.Value 'part number
.List(.ListCount - 1, 1) = rngToFind.Offset(0, 1).Value 'desc
.List(.ListCount - 1, 2) = rngToFind.Offset(0, 2).Value 'stor loc
.List(.ListCount - 1, 3) = rngToFind.Offset(0, 3).Value 'bin loc
.List(.ListCount - 1, 4) = rngToFind.Offset(0, 4).Value 'qty
.List(.ListCount - 1, 5) = rngToFind.Offset(0, 5).Value 'mfg
.List(.ListCount - 1, 6) = rngToFind.Offset(0, 7).Value 'pm name
End With
End If
Loop
End Sub
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules