I copy large amounts of filtered data (visible data and values only) from one workbook to another but the process is very slow. I would like to try bypassing the clipboard to see if that improves the speed but I keep getting the error Object does not support this property or method
. Here is the code that is failing:
ActiveSheet.SpecialCells(xlCellTypeVisible).Copy _
Destination:=Windows("Some Report").Worksheets( _
"Some Sheet").Range("A1").Values
I've tried different variations but receive the same error.
What about just setting the cells.value equal to each other? This little snippet assumes you want to copy the cells into the same destination cell, so you'd have to adjust for that if that's not what you're doing.
Private Sub worksheet_selectionchange(ByVal Target As Range)
Dim lastRow As Integer
Dim lastCol As Integer
Dim wb1 As Workbook
Dim ws1 As Worksheet
Dim ws2 As Worksheet
Set wb1 = ThisWorkbook
Set ws1 = wb1.Sheets(1)
Set ws2 = wb1.Sheets(2)
lastRow = ws1.Cells.Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
lastCol = ws1.Cells.Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Column
For i = 1 To lastRow: For j = 1 To lastCol
If ws1.Cells(i, j).Value > 5 And Not ws1.Cells(i, j).Hidden Then
ws2.Cells(i, j).Value = ws1.Cells(i, j).Value
End If
Next: Next
End Sub
Unfortunately without seeing much else of your code I can't prove much else, but this is the only alternative to copying and pasting that I know of.
I have done this without actually using the SpecialCells(xlCellTypeVisible) method and it copies and pastes perfectly. I first filter the data with an array, then I just use the Worksheets("Sheet1").Range("A1:" & last column & last row).Copy destination:=Worksheets("Sheet2").Range("E5") method and it works just fine on Office 2010. I did look into the SpecialCells(xlCellTypeVisible) method but it was never necessary.
Maybe if you put UsedRange.SpecialCells(xlCellTypeVisible).Copy it would work?
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.