我对任何一种编程方法都是陌生的,但是我试图删除包含某些文本的两个单元格之间的所有行,然后在电子表格中的所有行(〜13万行)中重复执行此操作。
示例
我要删除单元格B2和B7之间的所有行,基于这些单元格中的文本
非程序员有没有办法做到这一点? :)
答案 0 :(得分:0)
在此示例中,我假设在B列中没有两个“连续的标准运行->安装运行”,反之亦然。
初始工作表:
最后一页
这是代码:
Sub test()
'remove cells between two cells Standard run->Setup run and Setup run->Standard run
Dim count, i, numCols As Long
Dim startRemove, endRemove, startText, endText As String
Dim rng As Range
startText = "Standard run->Setup run" 'text where we begin to remove the cells
endText = "Setup run->Standard run" ' text where we finish to remove the cells
startRemove = "" 'in this variable we'll put the cell address of Standard run->Setup run Cells(2, 7).Address
endRemove = "" 'in this variable we'll put the cell address of Setup run->Standard run Cells(7, 7).Address
'-----control column B
'count how many rows
numCols = Range("B:B").Cells.SpecialCells(xlCellTypeConstants).count
For i = 1 To numCols
If Cells(i, 2) = startText Then ' control if current cell has Standard run->Setup run
startRemove = Cells(i, 2).Address
ElseIf Cells(i, 2) = endText Then ' control if current cell has Setup run->Standard run
endRemove = Cells(i, 2).Address
Range(startRemove & ":" & endRemove).Delete
startRemove = ""
endRemove = ""
End If
Next i
Range("B1:B" & numCols).Cells.SpecialCells(xlCellTypeBlanks).Delete Shift:=xlUp ' delete empty rows created
End Sub
希望这会有所帮助。
答案 1 :(得分:0)