Sub FilterData()
Dim lRow, lRowFiltered As Long
Application.ScreenUpdating = False
Sheet6.Range("B3:K13").ClearContents ' clearing old values
' Reset AutoFilter to get last row with data
Sheet7.Select
If ActiveSheet.AutoFilterMode Then
ActiveSheet.AutoFilterMode = False
End If
lRow = Cells(Rows.Count, 1).End(xlUp).Row
' Reset AutoFilters (incl new helper column
ActiveSheet.Range("A1").AutoFilter
' Change Column E Numbers to Text for filtering with wildcard
Range("E2:E" & lRow).Select
Selection.TextToColumns Destination:=Range("E2"), DataType:=xlDelimited, _
TextQualifier:=xlDoubleQuote, ConsecutiveDelimiter:=False, Tab:=True, _
Semicolon:=False, Comma:=False, Space:=False, Other:=False, FieldInfo _
:=Array(1, 2), TrailingMinusNumbers:=True
' Apply filters for columns 'E' & 'F'
With ActiveSheet.Cells(1, 1).CurrentRegion
.AutoFilter Field:=5, Criteria1:="=6*", Operator:=xlFilterValues
.AutoFilter Field:=6, Criteria1:="=*", Operator:=xlFilterValues
End With
lRowFiltered = Cells(Rows.Count, 1).End(xlUp).Row
If lRowFiltered < 2 Then
MsgBox "No data found to be copied", vbExclamation, "Data Empty"
Exit Sub
End If
Range("A2:J" & lRow).SpecialCells(xlCellTypeVisible).Copy
Sheet6.Select
Range("B3").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Application.CutCopyMode = False
On Error GoTo 0
' Reverse column E back from 'Text' to 'General'
Sheet7.Select
ActiveSheet.AutoFilterMode = False
Range("E2:E" & lRow).Select
Selection.TextToColumns Destination:=Range("E2"), DataType:=xlDelimited, _
TextQualifier:=xlDoubleQuote, ConsecutiveDelimiter:=False, Tab:=True, _
Semicolon:=False, Comma:=False, Space:=False, Other:=False, FieldInfo _
:=Array(1, 1), TrailingMinusNumbers:=True
Selection.NumberFormat = "General"
ActiveSheet.Range("A1").AutoFilter
Sheet6.Select
' Reverse column F back from 'Text' to 'General'
Columns("F:F").Select
Selection.TextToColumns Destination:=Range("F1"), DataType:=xlDelimited, _
TextQualifier:=xlDoubleQuote, ConsecutiveDelimiter:=False, Tab:=True, _
Semicolon:=False, Comma:=False, Space:=False, Other:=False, FieldInfo _
:=Array(1, 1), TrailingMinusNumbers:=True
Selection.NumberFormat = "General"
Application.CutCopyMode = False
Dim pastedRange As Range
Dim lRow2 As Long
lRow2 = Cells(Rows.Count, 2).End(xlUp).Row ' Find last used row in column B (A has formulas)
Call ResetBorders ' Reset borders before applying double ines to pasted range
Set pastedRange = Sheet6.Range("B3:K" & lRow2) ' Will automatically update to pasted range
' Apply double lined border to the outer edges of the range
With pastedRange
.Borders(xlEdgeTop).LineStyle = xlDouble
.Borders(xlEdgeTop).Color = RGB(0, 0, 0)
.Borders(xlEdgeTop).Weight = xlThick
.Borders(xlEdgeBottom).LineStyle = xlDouble
.Borders(xlEdgeBottom).Color = RGB(0, 0, 0)
.Borders(xlEdgeBottom).Weight = xlThick
.Borders(xlEdgeLeft).LineStyle = xlDouble
.Borders(xlEdgeLeft).Color = RGB(0, 0, 0)
.Borders(xlEdgeLeft).Weight = xlThick
.Borders(xlEdgeRight).LineStyle = xlDouble
.Borders(xlEdgeRight).Color = RGB(0, 0, 0)
.Borders(xlEdgeRight).Weight = xlThick
End With
Application.ScreenUpdating = True
End Sub
Sub ResetBorders()
' Set all internal lines to 'Thin - single line'
Range("B3:K13").Borders.LineStyle = Excel.XlLineStyle.xlContinuous
' Add 'thick' outside boarder for column K
Range("K2:K13").Select
With Selection
.Borders(xlEdgeTop).LineStyle = xlSingle
.Borders(xlEdgeTop).Color = RGB(0, 0, 0)
.Borders(xlEdgeTop).Weight = xlThick
.Borders(xlEdgeBottom).LineStyle = xlSingle
.Borders(xlEdgeBottom).Color = RGB(0, 0, 0)
.Borders(xlEdgeBottom).Weight = xlThick
.Borders(xlEdgeLeft).LineStyle = xlSingle
.Borders(xlEdgeLeft).Color = RGB(0, 0, 0)
.Borders(xlEdgeLeft).Weight = xlThick
.Borders(xlEdgeRight).LineStyle = xlSingle
.Borders(xlEdgeRight).Color = RGB(0, 0, 0)
.Borders(xlEdgeRight).Weight = xlThick
End With
End Sub
Bookmarks