Current i have an excel with roughly 200000+ records and i need to filter data based on a column. The column has around 5 values and i need to filter out 2 values in one sheet and the rest 3 to remain in the same sheet.
Now instead of using cell by cell comparison to check whether the value of the cell falls in any of the above 2 values and then cut paste the row into another sheet. This wouldn’t work with 200k+ records and simply hangs,.
Instead am planning to take the auto filter method. I tried using the ‘Record macro’ feature, but the problem is that it gives me some error like
“Excel cannot create or use the data range reference because its too complex.Try one of the following
Use data that can be selected in rectangle
Use data from the same sheet”
Moreover how to copy paste only the filtered values to another sheet? If I try to copy paste directly or special paste as ‘values’ then also even the hidden rows get copy pasted.
Below is the macro code i have been tampering around with
Sub Macro34()
'
' Macro34 Macro
'
'
Rows("1:1").Select
Selection.AutoFilter
ActiveSheet.Range("$A$1:$T$81335").AutoFilter Field:=6, Criteria1:="=242", _
Operator:=xlOr, Criteria2:="=244"
Cells.Select
Selection.Copy
ActiveWindow.SmallScroll Down:=21
Sheets("Sheet2").Select
ActiveWindow.SmallScroll Down:=-18
Range("A1").Select
ActiveSheet.Paste
Application.CutCopyMode = False
Selection.ClearContents
Range("A1").Select
Sheets("Sheet1").Select
Selection.Copy
Sheets("Sheet2").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Sheets("Sheet2").Select
ActiveWindow.SmallScroll Down:=93
Sheets("Sheet1").Select
ActiveWindow.SmallScroll Down:=-9
ActiveWindow.ScrollRow = 1
Rows("1:1").Select
Application.CutCopyMode = False
Selection.AutoFilter
End Sub
There might be some junk lines of code above as its generated using the ‘record macro’ feature.
Could someone please help me. The problem is the amount of data present in excel. Cant excel not handle this much data in VBA? Am using Excel 2007
Here’s your code cleaned up:
The key is that SpecialCells part.
Now, as much as I love a good autofilter copy/paste, when you’re dealing with that much data, you might want to look into using ADO, which would allow you to query your Excel worksheet using SQL.
A good overview of ADO in VBA is provided here: http://www.xtremevbtalk.com/showthread.php?t=217783.