I've been able to add more columns to the "search results" and a sorting option, the 'commented' line (the first with statement to sort C7 ascending) worked, but .SortFields.Add Key:=Range("E7"), Order:=xlDescending does not sort the dates correctly. Any ideas??
Also, I'm trying to figure out how to add boarders to the resultant list....but it ain't workin! Any suggestions??
Also, I'm trying to figure out how to add boarders to the resultant list....but it ain't workin! Any suggestions??
VBA Code:
Sub Search_criteria_pricing()
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("pricing")
Set sh2 = Sheets("search")
'
a = sh1.Range("A1:Q" & sh1.Range("A:Q").Find("*", , xlValues, , 1, 2).Row).Value2
sh2.Range("A8:H" & Rows.Count).ClearContents
ReDim b(1 To UBound(a, 1), 1 To 16)
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) & "*"
'j = sh2 columns, a = sh1 corresponding columns
' ///// need to add boarders to resultant list /////
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)
b(j, 4) = a(i, 9)
b(j, 5) = a(i, 12)
b(j, 6) = a(i, 14)
b(j, 7) = a(i, 15)
b(j, 8) = a(i, 16)
End If
Next i
If j > 0 Then sh2.Range("A8").Resize(j, 16).Value = b
'moves to top of displayed list
Range("A8").Select
'sort results by column C then E --- **** dates (col E) not sorting correctly
With ActiveSheet.Sort
'.SortFields.Add Key:=Range("C7"), Order:=xlAscending
.SortFields.Add Key:=Range("E7"), Order:=xlDescending
.SetRange Range("A7:H5555")
.Header = xlYes
.Apply
End With
End Sub