PDA

View Full Version : [SOLVED:] Delete rows when copying table



kippiebla
05-08-2020, 01:55 PM
I am not a star in Excel and certainly a newbie in VBA. In the attached file you see in worksheet "Source" in column C different reviews. Among these reviews are also "Error" and "Not good". The "Copy" worksheet should be a copy of the "Source" worksheet, but the rows with "Error" and "False" should not be copied. These rows may be left empty, but it would even be better of it is possible to leave them out entirely so that only 4 rows remain in worksheet "Copy".


I have been sent a code that should do it. That code is:


Sub Ja()
With Sheets("bron").Range("A4:C11") 'je bron
.Parent.AutoFilterMode = False 'filter uitzetten in blad
.AutoFilter Field:=3, Criteria1:=Array("Ja", "Ja goed", "Ja ok", "nog een andere reden"), Operator:=xlFilterValues 'array met alles dat wel meemag
.Copy Sheets("Kopie").Range("E4") 'doorkopieren
.Parent.AutoFilterMode = False 'filter uitzetten
End With
End Sub




But now I don't know what to do with that code at all. Where to put it. Can anyone help?

paulked
05-08-2020, 02:26 PM
That code does work, changing the language 1st!

kippiebla
05-09-2020, 02:28 PM
Thanks Paulked for your reaction. And happy to hear that the code does work! But what should I do? I have a Dutch version of Excel. And I changed the example file I posted in English. And VBA is always in English isn't it? So what should I do now. I checked your 67329-Example Copy Sheets.xlsm. But that gave on my laptop an error in the Macro line "Parent.AutoFilterMode = False 'filter uitzetten in blad". So what should I do? Hope you can help me!

The translations of the Dutch sentences in the macro are:
- filter uitzetten in blad: turn off the filter in sheet
- array met alles dat wel mee mag = array with everything that is allowed (to be copied?)
- door kopieren: copy further
- filter uitzetten: turn off the filter

macropod
05-09-2020, 02:41 PM
Cross-posted at: https://www.msofficeforums.com/excel-programming/44912-delete-rows-when-copying-table.html
Please read VBA Express' policy on Cross-Posting in Rule 3: http://www.vbaexpress.com/forum/faq.php?faq=new_faq_item#faq_new_faq_item3

paulked
05-09-2020, 02:45 PM
It doesn't matter what language they are in as long as the variables, sheet names etc match up. In this instance, make sure your Sheet Names "bron" and "kopie" match up with the names in the code.

Why you get an error there I don't know, all it is doing is clearing the filter after it has run. Did it make a new table on the copy sheet E4:G8?

kippiebla
05-10-2020, 12:19 AM
Thanks Paulked, got it working! Thanks a lot!

paulked
05-10-2020, 05:59 AM
You're welcome. You can mark it solved (Thread Tools at the top) :thumb

kippiebla
05-10-2020, 06:01 AM
Did it. Thanks!