One of the reasons your code is running slowly is that you are copying and pasting several columns separately and repeating the same process many times
Copy/Paste copies only filtered rows - so I have not included specialcells in the code
Instead of copying and pasting in bits
- firstly copy and paste the whole of the data values range to a temporary sheet
- then instead of copying and pasting each column, attribute the values instead
I am guessing that you have filter headers in row 7 and that you are copying all your filtered data range - if not
replace this in the code below
sh1.Range("A7").CurrentRegion.Copy
with
sh1.Range("A8:J391").Copy
and the Resize becomes Resize(lr) instead of Resize(lr - 1)
Create a temporary sheet and name it "Temp" and try replacing everything in your code below line On Error Resume Next (which you should no longer require)
Dim temp As Worksheet, lr As Long
Set temp = Sheets("Temp")
temp.Range("A1").PasteSpecial (xlPasteValues)
lr = temp.Range("A" & Cells.Rows.Count).End(xlUp).Row
With temp
Range("C" & Rows.Count).End(xlUp).Offset(1, 0).Resize(lr - 1) = .Range("I2:I" & lr).Value
Range("D" & Rows.Count).End(xlUp).Offset(1, 0).Resize(lr - 1) = .Range("C2:C" & lr).Value
Range("E" & Rows.Count).End(xlUp).Offset(1, 0).Resize(lr - 1) = .Range("H2:H" & lr).Value
Range("M" & Rows.Count).End(xlUp).Offset(1, 0).Resize(lr - 1) = .Range("D2:E" & lr).Value
Range("H" & Rows.Count).End(xlUp).Offset(1, 0).Resize(lr - 1) = .Range("F2:F" & lr).Value
Range("J" & Rows.Count).End(xlUp).Offset(1, 0).Resize(lr - 1) = .Range("G2:G" & lr).Value
Range("L" & Rows.Count).End(xlUp).Offset(1, 0).Resize(lr - 1) = .Range("J2:J" & lr).Value
End With
And do not forget to include ImranBhatti's suggestions - which avoid the sheet being recalculated and the display refreshed every time a value is changed by VBA
Bookmarks