I have a code that auto-fills down for 200 rows, then deletes the unused rows and sorts them based on data in some of the cells, however when it sorts it does the entire worksheet and not row 6 and onwards as I had intended, also for selecting the rows to delete I had to copy and paste the same code over and over i was wondering if there is a simpler way to do this. Thank you for any assistance you can give me.
Sub WireDataMacro()
Dim strOS As String
Dim strNS As String
strOS = ActiveSheet.Name
strNS = "Wire Data2 " & strOS
Sheets.Add(After:=ActiveSheet).Name = strNS
Sheets("Formulas").Select
Range("A1:Q6").Select
Selection.Copy
Sheets(strNS).Select
Range("a1:Q6").Select
ActiveSheet.PasteSpecial xlPasteFormulasAndNumberFormats
Rows(6).RowHeight = 15
Dim c As Range
For Each c In ActiveSheet.UsedRange
c = Replace(c, "WORKSHEET", strOS)
Next
Dim d As Range
For Each d In ActiveSheet.UsedRange
d = Replace(d, "##", "4")
Next
Dim e As Range
For Each e In ActiveSheet.UsedRange
e = Replace(e, Chr(34) & "=", "=")
Next
Range("A6").AutoFill Destination:=Range("A6:A200")
Range("B6").AutoFill Destination:=Range("B6:B200")
Range("C6").AutoFill Destination:=Range("C6:C200")
Range("D6").AutoFill Destination:=Range("D6:D200")
Range("E6").AutoFill Destination:=Range("E6:E200")
Range("F6").AutoFill Destination:=Range("F6:F200")
Range("G6").AutoFill Destination:=Range("G6:G200")
Range("H6").AutoFill Destination:=Range("H6:H200")
Range("I6").AutoFill Destination:=Range("I6:I200")
Range("J6").AutoFill Destination:=Range("J6:J200")
Range("K6").AutoFill Destination:=Range("K6:K200")
Range("L6").AutoFill Destination:=Range("L6:L200")
Range("M6").AutoFill Destination:=Range("M6:M200")
Range("N6").AutoFill Destination:=Range("N6:N200")
Range("O6").AutoFill Destination:=Range("O6:O200")
Range("P6").AutoFill Destination:=Range("P6:P200")
Range("Q6").AutoFill Destination:=Range("Q6:Q200")
With ActiveSheet
.AutoFilterMode = False
With Range("c1", Range("c" & Rows.Count).End(xlUp))
.AutoFilter 1, "0.00"
On Error Resume Next
.Offset(1).SpecialCells(12).EntireRow.Delete
End With
.AutoFilterMode = False
End With
With ActiveSheet
.AutoFilterMode = False
With Range("d1", Range("d" & Rows.Count).End(xlUp))
.AutoFilter 1, "*DR 2AWG*"
On Error Resume Next
.Offset(1).SpecialCells(12).EntireRow.Delete
End With
.AutoFilterMode = False
End With
With ActiveSheet
.AutoFilterMode = False
With Range("d1", Range("d" & Rows.Count).End(xlUp))
.AutoFilter 1, "*DR 4AWG*"
On Error Resume Next
.Offset(1).SpecialCells(12).EntireRow.Delete
End With
.AutoFilterMode = False
End With
With ActiveSheet
.AutoFilterMode = False
With Range("d1", Range("d" & Rows.Count).End(xlUp))
.AutoFilter 1, "*DR 6AWG*"
On Error Resume Next
.Offset(1).SpecialCells(12).EntireRow.Delete
End With
.AutoFilterMode = False
End With
With ActiveSheet
.AutoFilterMode = False
With Range("d1", Range("d" & Rows.Count).End(xlUp))
.AutoFilter 1, "*DR 8AWG*"
On Error Resume Next
.Offset(1).SpecialCells(12).EntireRow.Delete
End With
.AutoFilterMode = False
End With
With ActiveSheet
.AutoFilterMode = False
With Range("d1", Range("d" & Rows.Count).End(xlUp))
.AutoFilter 1, "*DR 10AWG*"
On Error Resume Next
.Offset(1).SpecialCells(12).EntireRow.Delete
End With
.AutoFilterMode = False
End With
With ActiveSheet
.AutoFilterMode = False
With Range("d1", Range("d" & Rows.Count).End(xlUp))
.AutoFilter 1, "*DR 12AWG*"
On Error Resume Next
.Offset(1).SpecialCells(12).EntireRow.Delete
End With
.AutoFilterMode = False
End With
With ActiveSheet
.AutoFilterMode = False
With Range("d1", Range("d" & Rows.Count).End(xlUp))
.AutoFilter 1, "*DR 1AWG*"
On Error Resume Next
.Offset(1).SpecialCells(12).EntireRow.Delete
End With
.AutoFilterMode = False
End With
Range("b6").CurrentRegion.Sort key1:=Range("b6"), order1:=xlAscending, Header:=xlGuess
End Sub
Bookmarks