This is a follow up to my original post. The script DanteAmor provided works great, but I'm wondering if it can be tweaked a bit so special characters (spaces, dashes, periods, slashes, quotation marks) in the "mdl# search" can be ignored and still find the correct item - which are all standardized to replace slashes, dashes, periods, with a 'space' and a space is added between a letter and number.
Below is one example I screenshotted for a visual representation. Here's a couple other possible variations for
Below is one example I screenshotted for a visual representation. Here's a couple other possible variations for
Mdl Search term | Result (what needs to be 'found') |
---|---|
2.0CW | 2 0 CW |
15M18 | 15 M 18 |
1-A1/DE | 1 A 1 DE |
S5-15 | S 5 15 |
7V 3-C | 7 V 3 C |
TP750 | TP 750 |
3D Alpha 1.2V | 3 D Alpha 1 2 V |
VBA Code:
Sub Search_criteria()
Dim sh1 As Worksheet, sh2 As Worksheet
Dim a As Variant, b As Variant
Dim i As Long, j As Long
Dim cad1 As String, cad2 As String, cad3 As String
'
Set sh1 = Sheets("MCT")
Set sh2 = Sheets("search")
'
a = sh1.Range("A1:C" & sh1.Range("A:C").Find("*", , xlValues, , 1, 2).Row).Value2
sh2.Range("A8:C" & Rows.Count).ClearContents
ReDim b(1 To UBound(a, 1), 1 To 3)
If sh2.[B2] <> "" Then cad1 = "*" & LCase(sh2.[B2].Value) & "*"
If sh2.[B3] <> "" Then cad2 = "*" & LCase(sh2.[B3].Value) & "*"
If sh2.[B4] <> "" Then cad3 = "*" & LCase(sh2.[B4].Value) & "*"
For i = 1 To UBound(a, 1)
If LCase(a(i, 1)) Like cad1 And LCase(a(i, 2)) Like cad2 And LCase(a(i, 3)) Like cad3 Then
j = j + 1
b(j, 1) = a(i, 1)
b(j, 2) = a(i, 2)
b(j, 3) = a(i, 3)
End If
Next i
If j > 0 Then sh2.Range("A8").Resize(j, 3).Value = b
'moves to top of displayed list
Range("A8").Select
End Sub