удаление строк между определенными ячейками, содержащими текст - Excel - PullRequest
0 голосов
/ 25 ноября 2018

Я абсолютно новичок в любом виде программирования, но я пытаюсь удалить все строки между двумя ячейками, содержащими определенный текст, а затем повторить это через все (~ 130 тыс. Строк) в электронной таблице.

Пример

Я хочу удалить все строки между ячейками B2 и B7, основываясь на тексте в этих ячейках Example, I want to remove all rows between cell B2 and B7, based on the text in those cells

Есть ли способ, которым непрограммист мог быбыть в состоянии сделать это?:)

Ответы [ 2 ]

0 голосов
/ 26 ноября 2018

Вот решение, которое не требует VBA

enter image description here

Я вставил формулу в столбец C, вы можете применить фильтр для удаления строк.

Формула в ячейке C2:

=IF(B2="Standard run->Setup run","start",IF(B2="Setup run->Standard run","end",IF(C1="start","remove",IF(C1="end","do not remove",C1))))
0 голосов
/ 25 ноября 2018

В этом примере я предполагаю, что в столбце B нет двух «последовательных стандартных прогонов -> прогонов установки» и наоборот.

исходный лист:

enter image description here

окончательный лист

enter image description here

Это код:

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

Надеюсь, это поможет.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...