Consulting

Results 1 to 7 of 7

Thread: problem deleting rows based on a condition in another workbook

  1. #1
    VBAX Regular
    Joined
    Mar 2009
    Posts
    38
    Location

    problem deleting rows based on a condition in another workbook

    hey all

    i'm using two workbooks "database.xls" and "ref to delete.xls"

    "ref to delete.xls" contains reference numbers to delete in "database.xls",
    when macro finds a that a ref number from "ref to delete.xls" in "database.xls", the entire row in "database.xls" that contains a ref. number in "ref to delete.xls" should be deleted.

    notice: ref. no column is "A", in both workbooks


    thanks in advance
    regards

  2. #2
    VBAX Regular
    Joined
    Mar 2009
    Posts
    38
    Location

    database attachment

    database.xls

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

    Public Sub ProcessData()
    Dim i As Long
    Dim LastRow As Long
    Dim cell As Range
    Dim sh As Worksheet

    Set sh = Workbooks("database.xls").Worksheets(1)
    With ActiveSheet

    LastRow = .Cells(.Rows.Count, "A").End(xlUp).Row
    For i = 2 To LastRow

    Set cell = Nothing
    cell = sh.Columns(1).Find(.Cells(i, "A").Value)
    If Not cell Is Nothing Then

    sh.Rows(cell.Row).Delete
    End If
    Next i
    End With
    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
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Just seen that this is cross-posted at MrExcel http://www.mrexcel.com/forum/showthr...=1#post1873173

    Here endeth m y assistance.
    ____________________________________________
    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

  5. #5
    VBAX Regular
    Joined
    Mar 2009
    Posts
    38
    Location
    hey xld

    thanks a lot

    regards

  6. #6

  7. #7
    VBAX Regular
    Joined
    Mar 2009
    Posts
    38
    Location
    hey

    in which file should insert the vba code? "database.xls" or "ref to delete.xls" ?

    thanks

Posting Permissions

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