简体   繁体   English

Excel VBA 在列中查找字符串然后删除工作表中所有剩余的行

[英]Excel VBA find string in column then delete all remaining row in worksheet

I am extremely new to VBA coding for excel and i really need to achieve this on 30 more workbooks containing each 250 worksheets...我对 Excel 的 VBA 编码非常陌生,我真的需要在包含每 250 个工作表的另外 30 个工作簿上实现这一点......

I need a VBA macro that can :我需要一个 VBA 宏,它可以:

  • find a string which match the entire cell contents and get row number (a)找到一个匹配整个单元格内容的字符串并获得行号(a)
  • find the number of row contain in the worksheet (b)找到工作表中包含的行数 (b)
  • then delete all rows from a to b然后删除从 a 到 b 的所有行

Can anyone help ?任何人都可以帮忙吗?

Thanks in advance !提前致谢 !

Well,好,

Just in case someone stubble on this post through search and/or google :以防万一有人通过搜索和/或谷歌在这篇文章上胡茬:

I posted it on Reddit and a kind soul gave me the answer :我把它贴在 Reddit 上,一个善良的人给了我答案:

Sub DeleteRowsAfterFinding3()

Dim i As Long
Dim rangeFound As Range
Dim ws As Worksheet

For Each ws In ActiveWorkbook.Worksheets

    Set rangeFound = ws.Range("A:A").Find("SOMETHING", Lookat:=xlWhole)

    If Not rangeFound Is Nothing Then
        For i = rangeFound.Row + 1 To ws.UsedRange.Rows.Count
            ws.Rows(rangeFound.Row + 1).Delete
        Next i
    End If

Next ws

End Sub

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Excel VBA从导入的工作表中删除列 - Excel VBA Delete Column from imported worksheet Excel VBA如何在工作表中找到最佳价格并将所有行放入另一个工作表 - Excel VBA How to find best price in worksheet and put all row to another worksheet Outlook VBA在Excel工作表中查找最后一行 - Outlook VBA find last Row in Excel Worksheet Excel VBA-查找具有值的所有单元格并删除整行(如果存在) - Excel VBA - Find all cells with value and delete the entire row if it exist 将 Excel 工作表中的所有单元格作为字符串 (VBA) - Take all cells in an Excel Worksheet in as String (VBA) 在工作簿中查找匹配的字符串,从不同的工作表中复制整行并替换原始行 - Excel VBA - Find matching string in workbook, copy entire row from different worksheet and replace original row - Excel VBA Excel VBA:如果列A在字符串中包含数字,则删除行 - Excel VBA: Delete row if Column A contains a number within the string VBA Excel 在列中查找字符串并偏移删除并重复 - VBA Excel Find string in column and offset delete and repeat Excel VBA-在列中查找字符串并在该行中插入数据 - Excel VBA - Find string in column and insert data in that row Excel VBA:在工作表的“偏移量”列中查找一个值以查找相同的值 - Excel VBA: Find a value in Worksheet, offset column to find same value
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM