Faster way to copy paste filtered data

B-Man

Board Regular
Joined
Dec 29, 2012
Messages
183
Office Version
  1. 2019
Platform
  1. Windows
this is my current Macro but it takes a while to process part of the data.... I only have 2000 rows for testing.
Is there a faster way? I normally use
VBA Code:
 .Range("").value =.Range("").value
but it doesn't seem to work when filtering the data...

VBA Code:
Sub SortData()


        Dim WsSource As Worksheet
        Dim WsDest As Worksheet
        Dim LastRow As Long

      Set WsSource = Sheets("Usage Import")
      Set WsDest = Sheets("Sheet1")
      LastRow = WsSource.Range("A" & WsSource.Rows.Count).End(xlUp).Row
     
  Application.ScreenUpdating = False
 

            With WsSource
               
                .Range("A1:E1").AutoFilter
               
                .Range("$A$1:$E" & LastRow).AutoFilter Field:=1, Criteria1:="Time Of Use"
               
                .Range("B:C").SpecialCells(xlCellTypeVisible).Copy
                WsDest.Range("A:B").PasteSpecial
               
                .Range("E:E").SpecialCells(xlCellTypeVisible).Copy
                WsDest.Range("C:C").PasteSpecial
                WsDest.Range("C1").Value = "TOU"
           

' More of the same formulas here just different filtering 

            End With

  Application.ScreenUpdating = True

End Sub
 
Last edited:
I seem to be overwriting the data rather than it moving the next column
using the same filter just grab data for solar and control load and move it to the next column.

whole point is a column for each data point rather than in one big long line and then not tripling up on date time etc. cuts the data into ~35000 rows
What you are describing is basically a pivot table. I would not be comfortable doing it the way you are doing it.
A Pivot table or Power Query table would ensure that if a From/To Date combination did not have all the every Register Type in it then it would align the matching ones for that From/To Date combination. There are no such guarantees with running the Filter multiple times and effectively pasting items next to each other.

i normally use C1 C2 etc so cells (1,1) etc had me stumped for a bit.
Cells(row, col) give you the option of using column number that you can increment with a counter so that you can use it in a loop.
ie put your register types in an array and loop through the array and add 1 or some other no to the column no on each iteration.
Some people use offset to achieve the same thing.
 
Upvote 0

Excel Facts

Format cells as date
Select range and press Ctrl+Shift+3 to format cells as date. (Shift 3 is the # sign which sort of looks like a small calendar).

Forum statistics

Threads
1,214,825
Messages
6,121,787
Members
449,049
Latest member
greyangel23

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