Copy and Paste Filtered cells in VBA

chromosome1984

New Member
Joined
Jan 2, 2015
Messages
2
DescriptionTypeTopperBase LayerAA1BB1CDD1TRUCK
7.5 FE 4" WIDEORANGE 840(1008 ) FE JOEY 8"H1-NG2H1 1 CPU
7.5 FE 4" WIDEORANGE 840(1008 ) FE JOEY 8"P1-DG34H1 11 CPU
7.5 FE 4" WIDEYELLOW DD 714(886) FE 8" IWC/SPLITH1-KG12H1 1 CPU
7.5 FE 4" WIDEYELLOW DD 714(886) FE 8" IWC/SPLITP1-KG12H11 CPU
7.5 FE 4" WIDEORANGE 840(1008 ) FE JOEY 8"DG34H1 2 CPU
7.5 FE 4" WIDEORANGE 840(1008 ) FE JOEY 8"H1-H1H1 1 CPU
7.5 FE 4" WIDEORANGE 840(1008 ) FE JOEY 8"P1-DG34H1 2 CPU
FE532 FESYP-H1SYP-BSP4 3 13 E01
FE532 FESYP-P275SYP-BSP 4 E01
FEPINK 700(814) FE ADJ CWC 6"SYP-P1SYP-BSP 1 1 E01
FEPINK 700(814) FE ADJ CWC 6"SYP-SW12SYP-BSP2 2 8 E01
7.5 FE 4" WIDEORANGE 840(1008 ) FE JOEY 8"DG34H11 E02
7.5 FE 4" WIDEORANGE 840(1008 ) FE JOEY 8"H1-H1H1 2 E02

<colgroup><col><col><col><col><col><col span="2"><col><col><col><col><col></colgroup><tbody>
</tbody>


Hello All,

Below is the code that I am using to get the o/p i need from an ERP dump to clean and make the file usable.
Sub Cleaner_FE()
'
' Cleaner_FE Macro
'


'
Columns("A:A").EntireColumn.AutoFit

'text to columns

Columns("A:A").Select
Selection.TextToColumns Destination:=Range("A1"), DataType:=xlFixedWidth, _
FieldInfo:=Array(Array(0, 1), Array(25, 1), Array(60, 1), Array(73, 1), Array(88, 1), _
Array(92, 1), Array(95, 1), Array(99, 1), Array(101, 1), Array(106, 1), Array(109, 1), _
Array(113, 1), Array(116, 1), Array(120, 1), Array(122, 1), Array(127, 1), Array(130, 1), _
Array(134, 1)), TrailingMinusNumbers:=True
Cells.Select
Cells.EntireColumn.AutoFit

'deleting empty or non useful cells

Columns("R:AD").Select
Selection.Delete Shift:=xlToLeft
Columns("P:P").Select
Selection.Delete Shift:=xlToLeft
Columns("N:N").Select
Selection.Delete Shift:=xlToLeft
Columns("L:L").Select
Selection.Delete Shift:=xlToLeft
Columns("J:J").Select
Selection.Delete Shift:=xlToLeft
Columns("H:H").Select
Selection.Delete Shift:=xlToLeft
Columns("F:F").Select
Selection.Delete Shift:=xlToLeft
ActiveWindow.ScrollColumn = 4
ActiveWindow.ScrollColumn = 3
ActiveWindow.ScrollColumn = 2
ActiveWindow.ScrollColumn = 1
Columns("B:B").Select
Selection.Copy
Columns("C:C").Select
Selection.Insert Shift:=xlToRight
Application.CutCopyMode = False
Selection.AutoFilter
ActiveSheet.Range("C:C").AutoFilter Field:=1, Criteria1:= _
"<>*truck*", Operator:=xlAnd, Criteria2:="<>*cpu*"
Selection.ClearContents
Rows("1:3").Select
Range("A3").Activate
Selection.Delete Shift:=xlUp
Rows("1:1").Select
Columns("C:C").Select
Selection.SpecialCells(xlCellTypeBlanks).Select
Selection.FormulaR1C1 = "=R[-1]C"
Columns("C:C").Select
Selection.Copy
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False


Columns("B:B").Select
Selection.Insert Shift:=xlToRight, CopyOrigin:=xlFormatFromLeftOrAbove
Cells.Select
Selection.AutoFilter
ActiveSheet.Range("$A$1:$T$731").AutoFilter Field:=1, Criteria1:= _
"<>*6"" IWC EDGE*", Operator:=xlAnd, Criteria2:="<>*7.5 FOAMEDGE 4"" WIDE*"
Range("B2").Select
ActiveCell.FormulaR1C1 = "Delete"
Range("B2").Select
Selection.Copy
Range("A2").Select
Selection.End(xlDown).Select
Columns("B:B").Select
ActiveSheet.Paste
Range("B2").Select
ActiveSheet.Range("$A:$T").AutoFilter Field:=1, Criteria1:="=*foam edge*", _
Operator:=xlAnd
Range("B24").Select
Application.CutCopyMode = False
ActiveCell.FormulaR1C1 = "Keep"
Range("B24").Select
Selection.Copy
Columns("B:B").Select
ActiveSheet.Paste
ActiveSheet.Range("$A:$T").AutoFilter Field:=1
ActiveSheet.Range("$A:$T").AutoFilter Field:=2, Criteria1:="Delete"
Cells.Select
Application.CutCopyMode = False
Selection.Delete Shift:=xlUp
Columns("B:B").Select
Selection.Delete Shift:=xlToLeft
Range("C1").Select



'Cleaning Truck Name & Route

Dim LR1 As Long
LR1 = ActiveSheet.UsedRange.Rows.Count
Range("L1").Select
ActiveCell.FormulaR1C1 = "=RIGHT(LEFT(RC[-9],5),3)"
Range("L1").Select
Selection.AutoFill Destination:=Range("L1:L" & LR1)


'insert a new row for headers

Rows("1:1").Select
Selection.Insert Shift:=xlDown, CopyOrigin:=xlFormatFromLeftOrAbove

'naming the headers

Range("A1").Select
ActiveCell.FormulaR1C1 = "Description"
Range("B1").Select
ActiveCell.FormulaR1C1 = "Type"
Range("C1").Select
ActiveCell.FormulaR1C1 = "Top"
Range("D1").Select
ActiveCell.FormulaR1C1 = "Base"
Range("E1").Select
ActiveCell.FormulaR1C1 = "T"
Range("F1").Select
ActiveCell.FormulaR1C1 = "T1"
Range("G1").Select
ActiveCell.FormulaR1C1 = "F"
Range("H1").Select
ActiveCell.FormulaR1C1 = "F1"
Range("I1").Select
ActiveCell.FormulaR1C1 = "Q"
Range("J1").Select
ActiveCell.FormulaR1C1 = "K"
Range("K1").Select
ActiveCell.FormulaR1C1 = "k1"
Range("L1").Select
ActiveCell.FormulaR1C1 = "Truck"
Range("A2").Select
End Sub



The issue i am running into is that this code is using the entire column as the range and making the code slow. Would like to improve this better.

I am not able to successfully copy and paste value of filtered cells into a new column either.

Please help me resolve this...

K
 

Excel Facts

Formula for Yesterday
Name Manager, New Name. Yesterday =TODAY()-1. OK. Then, use =YESTERDAY in any cell. Tomorrow could be =TODAY()+1.

Forum statistics

Threads
1,214,943
Messages
6,122,380
Members
449,080
Latest member
Armadillos

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top