Consulting

Results 1 to 4 of 4

Thread: Solved: Code to find match & remove data from 5 sheets

  1. #1
    VBAX Tutor
    Joined
    Jan 2006
    Posts
    248
    Location

    Solved: Code to find match & remove data from 5 sheets

    I have a userfom populated with names from sheet 1, what I want to happen is when a name is selected on the userform and the delete button is clicked that it will search sheets 2,3,4,5,6 for a match to the name from the userform and delete the data from each sheet with a match.

    The data that needs to be deleted is name from column A and all data in that row up to column W.

    I have attached a workbook with the userform and the other sheets.

    Thanks for any assistance.

  2. #2
    VBAX Tutor nst1107's Avatar
    Joined
    Nov 2008
    Location
    Monticello
    Posts
    245
    Location
    This does not account for multiple instances of a name or no instance of a name. It assumes that if there is an entry on Sheet1, there will be a corresponding entry on the rest of the sheets.[VBA]Private Sub CommandButton1_Click()
    Dim c As Range
    Dim ws As Worksheet
    If ComboBox1 = vbNullString Then Exit Sub
    For Each ws In ThisWorkbook.Worksheets
    If ws.Index = Sheet1.Index Then GoTo escape
    With ws.Columns("A")
    Set c = .Find(ComboBox1)
    If Not c Is Nothing Then ws.Rows(c.Row).Delete
    End With
    escape:
    Next
    End Sub
    [/VBA]

  3. #3
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    [vba]

    Private Sub CommandButton1_Click()
    Dim sh As Worksheet
    Dim cell As Range

    For Each sh In Worksheets(Array("Sheet2", "Sheet3", "Sheet4", "Sheet5", "Sheet6"))

    Set cell = Nothing
    Set cell = sh.Columns(1).Find(Me.ComboBox1.Value)
    If Not cell Is Nothing Then

    cell.EntireRow.Delete
    End If
    Next sh
    End Sub
    [/vba]
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  4. #4
    VBAX Tutor
    Joined
    Jan 2006
    Posts
    248
    Location
    Thank you both nst1007 and xld for your code, I think xld's code suits my situation best, thanks again to you both, I will mark this as solved.

Posting Permissions

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