Apparently, if this code works for one tab, just iterate on several, which can be done like this:
Dim Plan as Worksheet
For each Plan in ActiveWorkbook.Sheets ' Pressupondo que o arquivo com as planilhas é o que está ativo quando esta função for chamada; se não for, fazer referência ao arquivo de excel adequado.
'Aqui você cola seu código que funciona para uma planilha,
' só que usando a variável Plan para as referências.
' Por exemplo:
Plan.copy ' Em vez de Worksheets(Array("Plan1")).Copy
With Plan ' Em vez de With Sheets("Plan1")
'Pelo código acima, acho que só as duas linhas acima precisam
' de adaptação, as outras não mudam nada.
Next Plan
Just one question: you didn’t put all your code here, right? I ask this for two reasons:
1) You copy the spreadsheet without pasting anywhere, so that the instruction Copy
was lost/useless;
2) You delete several lines from the Plan1 spreadsheet from the original file, but do not compile the result elsewhere. If you run this code by iterating all worksheets in the form described above, you will end up with the original file without the deleted lines but still divided into different worksheets. To unify them in a single spreadsheet, you could copy the contents of each worksheet (property UsedRange
of each spreadsheet) and paste everything into one spreadsheet.
EDIT ABOUT THE PROPERTY USEDRANGE
:
UsedRange
is a property of the Spreadsheet object (WorkSheet
) that returns a range with the area in use. Therefore, to know the address of the range in use in the spreadsheet, you could use Plan.UsedRange.Address
, that returns a string with the address in use in the Plan spreadsheet. To find out the last line, you can use Plan.Cells.SpecialCells(xlCellTypeLastCell).Row
.
However, take care of the property UsedRange
. It usually resets each time it is used, so it is not interesting to make multiple references to the Usedrange of a spreadsheet. If you need to use it often, it’s best to assign the Usedrange to a Range type variable and work with it, or search in other ways (gives a search or question here in Stackoverflow, because this whole Dit no longer has to do with the main subject of this question).
First thanks for the help, the above Cod is presenting an error .... ERROR 438 ( Object does not accept this property or method ) About your questions let’s go. 1) With the data filtered and copied I create a new file and colo. 2) How do I use this method? ( Usedrange) Note: Inside the column " E " I have three cell types I need to copy only the "Cell 01" and delete the " Cell 02" "Cell 03". Copy the updated spreadsheet and generate a new file with the new data I will show you Cod below how I am doing
– John Hebert
About the mistake, it was my fault: the correct is
For Each Plan in ActiveWorkbook.Sheets
. I edited the answer. About Usedrange, I will edit the answer as well.– César Rodriguez
Finally, about item 1, what I wondered is that you copy the spreadsheet BEFORE making the changes, you know?
– César Rodriguez
Show! Thank you very much Cesar
– John Hebert