I'm trying to export a filtered named range to a new workbook. My named range contains a variable amount of rows with a '0' in a specific column. I'd like to exclude those rows (which contain a '0' in column 'F') from my selection before exporting them to the new workbook.
Below is the code I'm using to copy the named range and paste it into a new workbook. So far so good, but I've got no clue on how to exclude the rows with a '0' in column 'F'; currently, the whole named range is pasted into a new workbook.
Dim MyFileName As String
Dim CurrentWB As Workbook, TempWB As Workbook
Set CurrentWB = ActiveWorkbook
ActiveWorkbook.ActiveSheet.Range("my named range").Copy
Set TempWB = Application.Workbooks.Add(1)
With TempWB.Sheets(1).Range("A1")
.PasteSpecial xlPasteValues
.PasteSpecial xlPasteFormats
End With
Assuming you have already filtered your data and the zeros are hidden, change the following line:
ActiveWorkbook.ActiveSheet.Range("my named range").SpecialCells(xlCellTypeVisible).Copy
If you have not filtered, then use AutoFilter
ActiveWorkbook.ActiveSheet.Range("my named range").AutoFilter Field:=(number of field), Criteria1:="<>0"
followed by the line above...
Este artigo é coletado da Internet.
Se houver alguma infração, entre em [email protected] Delete.
deixe-me dizer algumas palavras