I'm pretty new to vba, but I do have some working code right now. I execute this code and it clears out cells on one sheet, references an assembly number on that sheet, searches through another sheet for that assembly number, copies the data I want relevant to that assembly number, and pastes in on the original sheet.
This works for the assembly number of interest when there is exactly one assembly number per cell in the spreadsheet database the code looks through. However, if the assembly number doesn't match the cell's exact value (which happens if there are multiple assemblies per cell) then the code passes up that cell and doesn't paste the relevant data.
Is there some way to look within a cell and have the macro recognize whether the assembly number is within an array of assembly numbers within a cell?
Is there a quick way to change the "If Sheets("Stencils").Cells(i, 8).Value = assembly Then" line so that it doesn't need an exact value?
Sub findstencil()
'1. declare variables
'2. clear old search results
'3. find records that match search criteria and paste them
Dim assembly As String 'Assembly number of interest, containts numbers, letters and dashes
Dim finalrow As Integer 'determines last row in database
Dim i As Integer 'row counter
'clears destination cells
Sheets("Search").Range("A7:H15").ClearContents
assembly = Sheets("Search").Range("A5").Value
finalrow = Sheets("Stencils").Range("C5000").End(xlUp).Row
For i = 5 To finalrow
If Sheets("Stencils").Cells(i, 8).Value = assembly Then
Sheets("Stencils").Cells(i, 3).Resize(1, 6).Copy
Sheets("Search").Range("B15").End(xlUp).Offset(1, 0).PasteSpecial xlPasteValues
End If
Next i
Sheets("Search").Range("A5").Select
End Sub