ไปยังเนื้อหาหลัก

จะลบแถวทั้งหมดที่มีข้อความเฉพาะภายในคอลัมน์ใน Google ชีตได้อย่างไร

สมมติว่าคุณมีช่วงข้อมูลในแผ่นงาน Google ตอนนี้คุณต้องการลบแถวตามค่าของเซลล์ในคอลัมน์ ตัวอย่างเช่นฉันต้องการลบแถวทั้งหมดที่มีข้อความ“ Complete” ใน Colum C บทความนี้จะพูดถึงวิธีแก้ปัญหาใน Google sheets

ลบแถวทั้งหมดที่มีข้อความเฉพาะภายในคอลัมน์ด้วยรหัสสคริปต์


ลบแถวทั้งหมดที่มีข้อความเฉพาะภายในคอลัมน์ด้วยรหัสสคริปต์

หากต้องการลบแถวทั้งหมดที่มีข้อความเฉพาะในคอลัมน์โค้ดสคริปต์ต่อไปนี้สามารถช่วยคุณได้โปรดดำเนินการดังนี้:

1. คลิก เครื่องมือ > โปรแกรมแก้ไขสคริปต์ดูภาพหน้าจอ:

doc ลบแถวที่มี 1

2. ในหน้าต่างรหัสที่เปิดใหม่คัดลอกและวางรหัสต่อไปนี้ลงในหน้าต่างรหัสเปล่าดูภาพหน้าจอ:

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 ลบแถวที่มี 2

หมายเหตุ: ในโค้ดด้านบน“ลบที่มี” คือชื่อแผ่นงานที่มีข้อมูลที่คุณต้องการลบ“ค: ค” คือคอลัมน์ที่มีข้อความเฉพาะที่คุณต้องการลบ“สมบูรณ์” คือข้อความเฉพาะที่คุณต้องการลบแถวตามความต้องการของคุณโปรดเปลี่ยนเป็นข้อความที่คุณต้องการ

3. จากนั้นบันทึกรหัสนี้แล้วคลิก วิ่ง ปุ่มในหน้าต่างรหัสเพื่อรันโค้ดสคริปต์นี้ดูภาพหน้าจอ:

doc ลบแถวที่มี 3

4. และแถวทั้งหมดที่มีข้อความเฉพาะ "เสร็จสมบูรณ์" ถูกลบพร้อมกันดูภาพหน้าจอ:

doc ลบแถวที่มี 4


ลบแถวทั้งหมดที่มีข้อความเฉพาะในแผ่นงาน Excel:

หากคุณต้องการลบแถวทั้งหมดที่มีค่าเฉพาะในคอลัมน์ไฟล์ Kutools สำหรับ Excel's เลือกเซลล์เฉพาะ คุณลักษณะสามารถช่วยให้คุณเลือกแถวทั้งหมดที่ตรงกับเกณฑ์จากนั้นคุณเพียงแค่ต้องลบแถวในครั้งเดียว

doc ลบแถวที่มี 5

Kutools สำหรับ Excel: ด้วย Add-in ของ Excel ที่มีประโยชน์มากกว่า 300 รายการให้ทดลองใช้ฟรีโดยไม่มีข้อ จำกัด ใน 30 วัน ดาวน์โหลดและทดลองใช้ฟรีทันที!

สุดยอดเครื่องมือเพิ่มผลผลิตในสำนักงาน

🤖 Kutools AI ผู้ช่วย: ปฏิวัติการวิเคราะห์ข้อมูลโดยยึดตาม: การดำเนินการที่ชาญฉลาด   |  สร้างรหัส  |  สร้างสูตรที่กำหนดเอง  |  วิเคราะห์ข้อมูลและสร้างแผนภูมิ  |  เรียกใช้ฟังก์ชัน Kutools...
คุณสมบัติยอดนิยม: ค้นหา เน้น หรือระบุรายการที่ซ้ำกัน   |  ลบแถวว่าง   |  รวมคอลัมน์หรือเซลล์โดยไม่สูญเสียข้อมูล   |   รอบโดยไม่มีสูตร ...
การค้นหาขั้นสูง: VLookup หลายเกณฑ์    VLookup หลายค่า  |   VLookup ข้ามหลายแผ่น   |   การค้นหาที่ไม่ชัดเจน ....
รายการแบบเลื่อนลงขั้นสูง: สร้างรายการแบบหล่นลงอย่างรวดเร็ว   |  รายการแบบหล่นลงขึ้นอยู่กับ   |  เลือกหลายรายการแบบหล่นลง ....
ผู้จัดการคอลัมน์: เพิ่มจำนวนคอลัมน์เฉพาะ  |  ย้ายคอลัมน์  |  สลับสถานะการมองเห็นของคอลัมน์ที่ซ่อนอยู่  |  เปรียบเทียบช่วงและคอลัมน์ ...
คุณสมบัติเด่น: กริดโฟกัส   |  มุมมองการออกแบบ   |   บาร์สูตรใหญ่    สมุดงานและตัวจัดการชีต   |  ห้องสมุดทรัพยากร (ข้อความอัตโนมัติ)   |  เลือกวันที่   |  รวมแผ่นงาน   |  เข้ารหัส/ถอดรหัสเซลล์    ส่งอีเมลตามรายการ   |  ซุปเปอร์ฟิลเตอร์   |   ตัวกรองพิเศษ (กรองตัวหนา/ตัวเอียง/ขีดทับ...) ...
ชุดเครื่องมือ 15 อันดับแรก12 ข้อความ เครื่องมือ (เพิ่มข้อความ, ลบอักขระ, ... )   |   50 + แผนภูมิ ประเภท (แผนภูมิ Gantt, ... )   |   40+ ใช้งานได้จริง สูตร (คำนวณอายุตามวันเกิด, ... )   |   19 การแทรก เครื่องมือ (ใส่ QR Code, แทรกรูปภาพจากเส้นทาง, ... )   |   12 การแปลง เครื่องมือ (ตัวเลขเป็นคำ, การแปลงสกุลเงิน, ... )   |   7 ผสานและแยก เครื่องมือ (แถวรวมขั้นสูง, แยกเซลล์, ... )   |   ... และอื่น ๆ

เพิ่มพูนทักษะ Excel ของคุณด้วย Kutools สำหรับ Excel และสัมผัสประสิทธิภาพอย่างที่ไม่เคยมีมาก่อน Kutools สำหรับ Excel เสนอคุณสมบัติขั้นสูงมากกว่า 300 รายการเพื่อเพิ่มประสิทธิภาพและประหยัดเวลา  คลิกที่นี่เพื่อรับคุณสมบัติที่คุณต้องการมากที่สุด...

รายละเอียด


แท็บ Office นำอินเทอร์เฟซแบบแท็บมาที่ Office และทำให้งานของคุณง่ายขึ้นมาก

  • เปิดใช้งานการแก้ไขและอ่านแบบแท็บใน Word, Excel, PowerPoint, ผู้จัดพิมพ์, Access, Visio และโครงการ
  • เปิดและสร้างเอกสารหลายรายการในแท็บใหม่ของหน้าต่างเดียวกันแทนที่จะเป็นในหน้าต่างใหม่
  • เพิ่มประสิทธิภาพการทำงานของคุณ 50% และลดการคลิกเมาส์หลายร้อยครั้งให้คุณทุกวัน!
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