Delete Data from Data Validation list and delete all other refernces

philkeoghan

New Member
Joined
Sep 23, 2009
Messages
13
Hi
I have a situation which I have made work sort of, but would like it to be dynamic and improved if possible though this forums great help
Thanks in advance :)

What I have is a list of names, these sometimes get deleted as people leave or added to when new staff come on board

What I need to be able to do is if I delete a name out of a named range(Master List) that is used in my Data Validation lists. I need to be able to find all refences to what I deleted and delete them too.
These lists are on multiple sheets.

This is what I have some up with from a bit of macro recording and a couple of changes in VBA

Code:
Sub DeleteValTest()
'
' DeleteValTest Macro
'

'
    Deleterow = ActiveCell.Row
    DeleteData = ActiveCell.Value
    Rows(Deleterow).Select
    Selection.Delete Shift:=xlUp
    Sheets("Sheet2").Select
    Range("D1").Select
    Selection.SpecialCells(xlCellTypeSameValidation).Select
    Cells.Replace What:=DeleteData, Replacement:="", LookAt:=xlPart, _
        SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
        ReplaceFormat:=False
End Sub

Sheet 1 has a list of names on the event of a cell having the delete key pressed I want this code to run.

It seems to work ok if my lists are just on sheet 2 in column d but they will be on other sheets as well in different areas

Any ideas on what I could do??
Thanks
Phil
 

Excel Facts

Did you know Excel offers Filter by Selection?
Add the AutoFilter icon to the Quick Access Toolbar. Select a cell containing Apple, click AutoFilter, and you will get all rows with Apple
This is how I would do this. Open your master list sheet, select a cell, then run this macro, it was ask you for confirmation, then it will clear every cell with that value in it.
Code:
Option Explicit

Sub DeleteValidatedSelectionFromAllSheets()
Dim MyVal As String
Dim valFIND As Range
Dim ws As Worksheet

MyVal = ActiveCell.Value
If MsgBox("Search all sheets for instances of '" & MyVal & "' and remove them?" _
    & vbLf & "This value will be removed from this sheet as well.  Proceed?", _
    vbYesNo + vbQuestion) = vbNo Then Exit Sub
    
On Error Resume Next
For Each ws In Worksheets
        Do
            Set valFIND = ws.Cells.Find(MyVal, LookIn:=xlValues, LookAt:=xlWhole)
            If Not valFIND Is Nothing Then
                valFIND = ""
                Set valFIND = Nothing
            Else
                Exit Do
            End If
        Loop
Next ws

End Sub
 
Upvote 0

Forum statistics

Threads
1,224,503
Messages
6,179,136
Members
452,890
Latest member
Nikhil Ramesh

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top