如何根据单元格值删除行 [英] How to delete row based on cell value
问题描述
我有一个工作表,我需要根据单元格值删除行。
要检查的单元格在列A ..
如果单元格包含 - ..删除行
我找不到办法这样做..我打开一个工作簿,将所有内容复制到另一个工作簿,然后删除整个行和列,但根据单元格值必须删除特定的行。
需要帮助。 p>
更新
p>
截图非常有帮助 - 以下代码将执行此操作(假设数据位于A列中的A1):
Sub RemoveRows()
Dim i As Long
i = 1
尽管i< = ThisWorkbook.ActiveSheet.Range(A1)。CurrentRegion.Rows.Count
如果InStr(1,ThisWorkbook.ActiveSheet.Ce lls(i,1).Text, - ,vbTextCompare)> 0然后
ThisWorkbook.ActiveSheet.Cells(i,1).EntireRow.Delete
Else
i = i + 1
结束如果
循环
End Sub
共享示例文件: https://www.dropbox.com/s/2vhq6vw7ov7ssya/RemoweDashRows.xlsm
I have a worksheet, I need to delete rows based on cell value ..
Cells to check are in Column A ..
If cell contains "-" .. Delete Row
I can't find a way to do this .. I open a workbook, copy all contents to another workbook, then delete entire rows and columns, but there are specific rows that has to be removed based on cell value.
Need Help Here.
UPDATE
Sample of Data I have
The screenshot was very helpful - the following code will do the job (assuming data is located in column A starting A1):
Sub RemoveRows()
Dim i As Long
i = 1
Do While i <= ThisWorkbook.ActiveSheet.Range("A1").CurrentRegion.Rows.Count
If InStr(1, ThisWorkbook.ActiveSheet.Cells(i, 1).Text, "-", vbTextCompare) > 0 Then
ThisWorkbook.ActiveSheet.Cells(i, 1).EntireRow.Delete
Else
i = i + 1
End If
Loop
End Sub
Sample file is shared: https://www.dropbox.com/s/2vhq6vw7ov7ssya/RemoweDashRows.xlsm
这篇关于如何根据单元格值删除行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!