Предположим, есть две таблицы: первая - master
, в которой есть все ваши уникальные ключи, а вторая - keys
.
Далее предположим, что данные настроены следующим образом:
**Master** **Keys**
A B A B
1 ABC1 other info... ABC1 other info...
2 ABC2 other info... ABC1 other info...
3 ABC3 other info... ABC2 other info...
4 ABC4 other info... ABC2 other info...
5 ABC5 other info... ABC2 other info...
ABC3 other info...
ABC4 other info...
Если вы выберете ключ в master
, который хотите удалить, и запустите следующий код, это удалит выбранный ключ из master
, а затем перебирает keys
и удалит все строки с таким же ключом:
Sub DeleteKeys()
Dim KeyID As String, KeysLastRow As Long, rw As Long
KeyID = Selection.Value
KeysLastRow = Worksheets("keys").Range("A1").End(xlDown).Row //Get last row in `keys` column A
Selection.EntireRow.Delete //Delete selected key (and row) in `master`
With Worksheets("keys") //Loop through `keys` deleting all matching keys
For rw = KeysLastRow To 1 Step -1
If .Cells(rw, 1).Value = KeyID Then
.Cells(rw, 1).EntireRow.Delete
End If
Next rw
End With
End Sub
Надеюсь, это поможет вам начать.