using resize ?

Danny54

Active Member
Joined
Jul 3, 2019
Messages
295
Office Version
  1. 365
Platform
  1. Windows
I have the following code which sets a range based on data being in the last column, however after running the autofilter a few lines later, the rows meeting the criteria have no data in the last column and are not copied to the new sheet.

How could i get all the records after the autofilter is applied?

My thought would be to change the for each and use column a to determine how many rows are in the autofilter
then do a resize before the copy??

Suggestions would be appreciated.

Thanks



For Each rfl In .Range(.Cells(1, .Columns.Count), .Cells(.Rows.Count, .Columns.Count).End(xlUp))

collection = rfl.Text
Set wsNew = Workbooks.Add
sfilename = "Trending " & collection & ".xlsx"
ActiveWorkbook.SaveAs opath & "" & sfilename
Application.DisplayAlerts = False
ws.Activate

rData.AutoFilter Field:=1, Criteria1:=collection

rData.Copy

Windows(sfilename).Activate
ActiveCell.PasteSpecial Paste:=xlPasteValues
ActiveWorkbook.Close SaveChanges:=True

rData.AutoFilter Field:=1 'reset selection to show all
 

Excel Facts

Links? Where??
If Excel says you have links but you can't find them, go to Formulas, Name Manager. Look for old links to dead workbooks & delete.
Hello,

You could test with a new variable rFiltered ...

Set rFiltered = rData.SpecialCells(xlCellTypeVisible)

Hope this will help
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,175
Members
453,021
Latest member
Justyna P

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