Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/vba/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Excel 删除两行之间具有特定单词的所有行_Excel_Vba - Fatal编程技术网

Excel 删除两行之间具有特定单词的所有行

Excel 删除两行之间具有特定单词的所有行,excel,vba,Excel,Vba,我们有许多excel表格,其中有近40000条与地质数据有关的记录。在该excel中,数据的最后一个参数(标准)将是“颜色表:” 比如: 从第59行开始,下一个数据的下一个参数将开始…并且再次 Row 88 Colour Table: (2 Entries) Row 89 0: 1,56,76 .. .. .. Row 102 Files: XXXXX 所以,我的问题是:如何删除位于包含文本的行之间的所有行:Color Table&包含文本文件的行: 了解VBA的一些基本知识。但我不知道该怎

我们有许多excel表格,其中有近40000条与地质数据有关的记录。在该excel中,数据的最后一个参数(标准)将是“颜色表:”

比如:

从第59行开始,下一个数据的下一个参数将开始…并且再次

Row 88  Colour Table: (2 Entries)
Row 89 0: 1,56,76
..
..
..
Row 102 Files: XXXXX
所以,我的问题是:如何删除位于包含文本的行之间的所有行:
Color Table
&包含文本
文件的行:


了解VBA的一些基本知识。但我不知道该怎么做

还不能测试它,但我认为这应该是可行的:

Dim FoundCellColor As Range
Dim FoundCellFiles As Range
Dim colorArray (0) As Integer
Dim fileArray (0) As Integer
Dim i As Integer
Dim k As Integer

i = 0

Application.ScreenUpdating = False

' Set your range here, placeholder A:A
Set FoundCellColor = Range("A:A").Find(what:="Color Table")
Set FoundCellFiles = Range("A:A").Find(what:="Files")

Do Until FoundCellColor Is Nothing
    Redim Preserve colorArray(i)
    Redim Preserve fileArray(i)

    colorRow = FoundCellColor.Row
    fileRow = FoundCellFiles.Row

    colorArray(i) = colorRow
    fileArray(i) = fileRow

    Set FoundCellColor = Range("A:A").FindNext
    Set FoundCellFiles = Range("A:A").FindNext

    i = i + 1
Loop

For k = 0 To ThisWorkbook.Worksheets(1).UsedRange.Rows.Count

    If UBound(Filter(colorArray, k)) < 0 AND UBound(Filter(fileArray, k)) < 0 Then ThisWorkbook.Worksheets(1).Rows(k).Delete

Next
Dim FoundCellColor作为范围
将FoundCellFiles设置为范围
Dim colorArray(0)作为整数
Dim fileArray(0)为整数
作为整数的Dim i
将k变为整数
i=0
Application.ScreenUpdating=False
'在此处设置范围,占位符A:A
设置FoundCellColor=Range(“A:A”)。查找(内容:=“颜色表”)
设置FoundCellFiles=Range(“A:A”)。查找(内容:=“文件”)
直到颜色什么都不是
Redim保留颜色数组(i)
Redim保留文件数组(i)
colorRow=FoundCellColor.Row
fileRow=FoundCellFiles.Row
colorArray(i)=colorRow
fileArray(i)=fileRow
设置FoundCellColor=Range(“A:A”)。FindNext
设置FoundCellFiles=Range(“A:A”)。FindNext
i=i+1
环
对于k=0,请访问此工作簿。工作表(1)。UsedRange.Rows.Count
如果UBound(Filter(colorArray,k))<0且UBound(Filter(fileArray,k))<0,则此工作簿.工作表(1).行(k).删除
下一个

注意:我假设每个“颜色表”都有相应的“文件”部分。如果情况并非如此,您必须相应地调整代码。

Thanka mate。但是它显示了在这一点上的语法错误ReDim Preserve colorArray(i)ReDim fileArray colorArray(j)我甚至不知道这个colorArray会做什么。这不是和颜色值有关吗。我可以知道我们为什么使用这个吗?当“颜色表”字符串出现时,颜色数组将存储行号。文件数组也是如此。最后,您将删除不在这些数组中的每一行。结果应该是你所要求的。我修正了代码中的两个输入错误,现在可能可以用了。我稍后会亲自测试
Dim FoundCellColor As Range
Dim FoundCellFiles As Range
Dim colorArray (0) As Integer
Dim fileArray (0) As Integer
Dim i As Integer
Dim k As Integer

i = 0

Application.ScreenUpdating = False

' Set your range here, placeholder A:A
Set FoundCellColor = Range("A:A").Find(what:="Color Table")
Set FoundCellFiles = Range("A:A").Find(what:="Files")

Do Until FoundCellColor Is Nothing
    Redim Preserve colorArray(i)
    Redim Preserve fileArray(i)

    colorRow = FoundCellColor.Row
    fileRow = FoundCellFiles.Row

    colorArray(i) = colorRow
    fileArray(i) = fileRow

    Set FoundCellColor = Range("A:A").FindNext
    Set FoundCellFiles = Range("A:A").FindNext

    i = i + 1
Loop

For k = 0 To ThisWorkbook.Worksheets(1).UsedRange.Rows.Count

    If UBound(Filter(colorArray, k)) < 0 AND UBound(Filter(fileArray, k)) < 0 Then ThisWorkbook.Worksheets(1).Rows(k).Delete

Next