Przejdź do głównej zawartości

Jak usunąć wszystkie wiersze zawierające określony tekst w kolumnie w arkuszach Google?

Przypuśćmy, że masz zakres danych w arkuszu Google, teraz chciałbyś usunąć wiersze na podstawie wartości komórek w kolumnie. Na przykład chcę usunąć wszystkie wiersze, które zawierają tekst „Complete” w kolumnie C. W tym artykule omówię, jak rozwiązać ten problem w arkuszach Google.

Usuń wszystkie wiersze zawierające określony tekst w kolumnie z kodem skryptu


Usuń wszystkie wiersze zawierające określony tekst w kolumnie z kodem skryptu

Aby usunąć wszystkie wiersze, które zawierają określony tekst w kolumnie, poniższy kod skryptu może wyświadczyć ci przysługę, wykonaj następujące czynności:

1. Kliknij Tools > Edytor skryptówzobacz zrzut ekranu:

doc usuń wiersze zawierające 1

2. W nowym otwartym oknie kodu skopiuj i wklej następujący kod do pustego okna kodu, zobacz zrzut ekranu:

function deleteRows() {
  var ss = SpreadsheetApp.getActiveSpreadsheet();
  var s = ss.getSheetByName('delete containing');
  var r = s.getRange('C:C');
  var v = r.getValues();
  for(var i=v.length-1;i>=0;i--)
    if(v[0,i]=='Complete')
      s.deleteRow(i+1);
};

doc usuń wiersze zawierające 2

Note: W powyższym kodzie „usuń zawierające”To nazwa arkusza zawierającego dane, które chcesz usunąć,„C: C”To kolumna z określonym tekstem, z którego chcesz usunąć,„Absolutna”To konkretny tekst, na podstawie którego chcesz usunąć wiersze, zmień je zgodnie z potrzebami.

3. Następnie zapisz ten kod, a następnie kliknij run przycisk w oknie kodu, aby wykonać ten kod skryptu, patrz zrzut ekranu:

doc usuń wiersze zawierające 3

4. Wszystkie wiersze zawierające określony tekst „Complete” zostały usunięte od razu, patrz zrzut ekranu:

doc usuń wiersze zawierające 4


Usuń wszystkie wiersze zawierające określony tekst w arkuszu programu Excel:

Jeśli chcesz usunąć wszystkie wiersze, które zawierają określoną wartość w kolumnie, rozszerzenie Kutools dla programu Excel's Wybierz określone komórki funkcja może pomóc Ci wybrać wszystkie wiersze spełniające kryteria, a następnie wystarczy usunąć wiersze naraz.

doc usuń wiersze zawierające 5

Kutools dla programu Excel: z ponad 300 poręcznymi dodatkami do programu Excel, które można wypróbować bez ograniczeń w ciągu 30 dni. Pobierz i bezpłatną wersję próbną teraz!

Najlepsze narzędzia biurowe

🤖 Pomocnik AI Kutools: Zrewolucjonizuj analizę danych w oparciu o: Inteligentne wykonanie   |  Wygeneruj kod  |  Twórz niestandardowe formuły  |  Analizuj dane i generuj wykresy  |  Wywołaj funkcje Kutools...
Popularne funkcje: Znajdź, wyróżnij lub zidentyfikuj duplikaty   |  Usuń puste wiersze   |  Łącz kolumny lub komórki bez utraty danych   |   Okrągły bez wzoru ...
Super wyszukiwanie: Wiele kryteriów VLookup    Wiele wartości VLookup  |   Przeglądanie pionowe na wielu arkuszach   |   Wyszukiwanie rozmyte ....
Zaawansowana lista rozwijana: Szybko twórz listę rozwijaną   |  Zależna lista rozwijana   |  Lista rozwijana wielokrotnego wyboru ....
Menedżer kolumn: Dodaj określoną liczbę kolumn  |  Przesuń kolumny  |  Przełącz stan widoczności ukrytych kolumn  |  Porównaj zakresy i kolumny ...
Polecane funkcje: Fokus siatki   |  Widok projektu   |   Duży pasek formuły    Menedżer skoroszytów i arkuszy   |  Biblioteka zasobów (Automatyczny tekst)   |  Selektor dat   |  Połącz arkusze   |  Szyfruj/odszyfruj komórki    Wysyłaj e-maile według listy   |  Super filtr   |   Specjalny filtr (filtruj pogrubienie/kursywa/przekreślenie...) ...
15 najlepszych zestawów narzędzi12 Tekst Tools (Dodaj tekst, Usuń znaki, ...)   |   50 + Wykres rodzaje (Wykres Gantta, ...)   |   40+ Praktyczne Wzory (Oblicz wiek na podstawie urodzin, ...)   |   19 Wprowadzenie Tools (Wstaw kod QR, Wstaw obraz ze ścieżki, ...)   |   12 Konwersja Tools (Liczby na słowa, Przeliczanie walut, ...)   |   7 Połącz i podziel Tools (Zaawansowane wiersze łączenia, Podział komórki, ...)   |   ... i więcej

Zwiększ swoje umiejętności Excela dzięki Kutools for Excel i doświadcz wydajności jak nigdy dotąd. Kutools dla programu Excel oferuje ponad 300 zaawansowanych funkcji zwiększających produktywność i oszczędzających czas.  Kliknij tutaj, aby uzyskać funkcję, której najbardziej potrzebujesz...

Opis


Karta Office wprowadza interfejs z zakładkami do pakietu Office i znacznie ułatwia pracę

  • Włącz edycję i czytanie na kartach w programach Word, Excel, PowerPoint, Publisher, Access, Visio i Project.
  • Otwieraj i twórz wiele dokumentów w nowych kartach tego samego okna, a nie w nowych oknach.
  • Zwiększa produktywność o 50% i redukuje setki kliknięć myszką każdego dnia!
Comments (16)
Rated 5 out of 5 · 1 ratings
This comment was minimized by the moderator on the site
This formula work for all column A and check all cells that contain some text > 0 and delete only the rows that contain some text in cells > 0

function deleteRows() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var s = ss.getSheetByName('Sheet_name_here);
var r = s.getRange('A:A');
var v = r.getValues();
for(var i=v.length-1;i>=0;i--)
if(v[0,i]>'0')
s.deleteRow(i+2);
};
Rated 5 out of 5
This comment was minimized by the moderator on the site
Bonjour, j'aime beaucoup ce script. Moi je cherche un script qui permet de supprimer automatiquement tous les éléments ou contenus d'une colonne après chaque 1 min. Pas supprimer la colonne, mais le contenu de la colonne. Pouvez vous m'aider ?
This comment was minimized by the moderator on the site
How can I make this more versatile?

LEt's say that I create a list of blacklisted words in Sheet1 and I want to delete all the rows in Sheet2 that contain that words in column A. I'm totally stuck on this on Google Sheets
This comment was minimized by the moderator on the site
Any luck with this??
This comment was minimized by the moderator on the site
I fixed this for myself using the following.
The reason it is not working is because the v returns an array with only one item [0]
I also used Javascript .includes() so that you can delete records that "Contain" that text.


function deleteRows() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var s = ss.getSheetByName('default');
var r = s.getRange('A:A');
var v = r.getValues();
for(var i=v.length-1;i>=1;i--)
if(v[i][0].includes("appleid.com")) {
console.log('deleted row ' + v[i][0]);
s.deleteRow(i+1);
}
};
This comment was minimized by the moderator on the site
Thank you so much. Works great for me
This comment was minimized by the moderator on the site
Great job, working seamlessly.
This comment was minimized by the moderator on the site
Figured it out, but having trouble making it work for larger sheets since it's exceeding maximum runtime. Basically, the data that was being returned for 'v' was an 'object' type so you had to JSON.stringify() it first in order to detect values.
<div data-tag="code">function deleteRows() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var s = ss.getSheetByName('REPLACE WITH NAME OF SHEET');
var r = s.getRange('C:C'); // Replace 'C:C' to be the column you want to replace like start:end
var v = r.getValues();
for(var i=v.length-1;i>=0;i--) {
if(JSON.stringify(v[i]).includes('REPLACE WITH THE CHAR YOU WANT TO REPLACE')) {
s.deleteRow(i+1);
}
}
};
This comment was minimized by the moderator on the site
Why use the comma operator in v[0,i] ?
This comment was minimized by the moderator on the site
This seems to work only if a cell contains only the text specified. I want to delete rows with cells that contain other text including the text specific. I have a bunch of email addresses and want to be rid of rows containing Gmail addresses, therefore I'm looking for cells containing 'gmail.com'.

No luck here.
This comment was minimized by the moderator on the site
Replace this line: if(v[0,i]=='Complete')
With this: if(v[0,i].indexOf('gmail') > -1)
This comment was minimized by the moderator on the site
Doesn't work for me, either.
This comment was minimized by the moderator on the site
I tried that. It's still not working.
This comment was minimized by the moderator on the site
Hello,
Can modify the below code to delete the coloured row instead of text


function deleteRows() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var s = ss.getSheetByName('delete containing');
var r = s.getRange('C:C');
var v = r.getValues();
for(var i=v.length-1;i>=0;i--)
if(v[0,i]=='Complete')
s.deleteRow(i+1);
};
This comment was minimized by the moderator on the site
Hello,
Can I modify the below code to delete a coloured cell instead of specific text:


function deleteRows() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var s = ss.getSheetByName('delete containing');
var r = s.getRange('C:C');
var v = r.getValues();
for(var i=v.length-1;i>=0;i--)
if(v[0,i]=='Complete')
s.deleteRow(i+1);
};
This comment was minimized by the moderator on the site
Does nothing at all, not sure how to fix this.
There are no comments posted here yet
Please leave your comments in English
Posting as Guest
×
Rate this post:
0   Characters
Suggested Locations