+ Reply to Thread
Results 1 to 6 of 6

Delete row - but to include any cells that have data validation / lists applied.

  1. #1
    Registered User
    Join Date
    11-12-2018
    Location
    Cornwall, England
    MS-Off Ver
    Excel 2016 (Office 365 ProPlus)
    Posts
    58

    Lightbulb Delete row - but to include any cells that have data validation / lists applied.

    Hi - I currently have the below macro which works really well in deleting entire rows. It first highlights the selected rows for deletion, and then prompts a message box for users to confirm or cancel deletion. Neat

    What I have noticed though is that once the rows are deleted, any cells that had lists applied to them (although they are being 'cleared') are not having the data validation / drop down lists removed.
    Is there any additional code I can add to clear these too? Thanks in advance, Matt.


    Private Sub Remove_Recipient_Click()

    Dim c As Range, DltRng As Range
    For Each c In Selection
    If DltRng Is Nothing Then
    Set DltRng = c
    Else
    Set DltRng = Union(c, DltRng)
    End If
    Next c
    If Not DltRng Is Nothing Then DltRng.EntireRow.Interior.ColorIndex = 6
    Rply = MsgBox("Warning - This can not be undone!" & vbNewLine & vbNewLine & "Are the highlighted row(s) the ones you want to delete?" & vbNewLine & vbNewLine & "If not click NO and first select any cell from the appropriate row(s)", vbYesNo)
    If Rply = vbYes Then
    DltRng.EntireRow.Delete
    ActiveCell.Select
    Else
    DltRng.EntireRow.Interior.ColorIndex = xlNone
    MsgBox "No rows were deleted."
    End If
    End Sub

  2. #2
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,659

    Re: Delete row - but to include any cells that have data validation / lists applied.

    Your code should delete the DV Lists. If there are DV Lists in the rows below, those rows move up to replace the deleted rows.

    If you just want to clear the rows, replace .Delete with .Clear

    Here is another version of your code...
    Please Login or Register  to view this content.
    Last edited by AlphaFrog; 12-06-2018 at 07:34 AM.
    Surround your VBA code with CODE tags e.g.;
    [CODE]your VBA code here[/CODE]
    The # button in the forum editor will apply CODE tags around your selected text.

  3. #3
    Registered User
    Join Date
    11-12-2018
    Location
    Cornwall, England
    MS-Off Ver
    Excel 2016 (Office 365 ProPlus)
    Posts
    58

    Re: Delete row - but to include any cells that have data validation / lists applied.

    AlphaFrog - ah I see!!

    Your code is far more simplified than mine so I have implemented straight away and it works just the same so thank you

    You are right about the DV cells too, on further interrogation they seem to be added when I run my 'Add new row' macro (see below). Because this is inserting a row to the bottom of a table I think its copying the DV down too. Wonder if there is a way to stop this to save having to delete more rows every time?

    I will attach the file to assist with the above explanation!

    Private Sub New_Row_Click()

    Range("A6:L6").Copy
    Range("B" & Rows.Count).End(xlUp).Select
    ActiveCell.EntireRow.Offset(1, 0).Insert
    Application.CutCopyMode = False

    Range("B5").End(xlDown).Select

    MsgBox "New Document added successfully "

    End Sub
    Attached Files Attached Files

  4. #4
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,659

    Re: Delete row - but to include any cells that have data validation / lists applied.

    When you add a new row at the bottom, you don't want it to have DV Lists?

    If Yes...
    Please Login or Register  to view this content.

  5. #5
    Registered User
    Join Date
    11-12-2018
    Location
    Cornwall, England
    MS-Off Ver
    Excel 2016 (Office 365 ProPlus)
    Posts
    58

    Re: Delete row - but to include any cells that have data validation / lists applied.

    Thanks again for looking at this.

    I definitely do want the new row to have them, but not the row under this.

    For some reason when adding a new row, both the new row and the one beneath this BOTH get the DV's applied???

  6. #6
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,659

    Re: Delete row - but to include any cells that have data validation / lists applied.

    I don't follow; "the new row to have them, but not the row under this. "

    The code I did just adds a row at the bottom of the table.

    Going to work now.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Default Value in Multiple Data Validation lists based on another cells value
    By Angelammarten in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 04-04-2016, 10:38 PM
  2. Using VLOOKUP when Data Validation is Applied
    By HangMan in forum Excel Formulas & Functions
    Replies: 7
    Last Post: 07-12-2015, 05:05 AM
  3. Replies: 2
    Last Post: 09-07-2013, 03:55 AM
  4. how to ignore blank cells in creatig dropdown lists (validation lists)
    By Elainefish in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 04-02-2013, 07:45 AM
  5. Replies: 6
    Last Post: 01-09-2012, 02:29 AM
  6. Replies: 3
    Last Post: 09-02-2010, 03:04 AM
  7. Replies: 2
    Last Post: 07-09-2010, 12:34 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1