Consulting

Results 1 to 4 of 4

Thread: Checking & Deleting

  1. #1

    Checking & Deleting

    Hi

    I have a workbook with 2 worksheets. In Col A of both sheets is a ref number. I need to check both sheets and if the ref number appears on both sheets, and there is no data (currency figure) in Col E of Sheet 1 delete the row, but if there is data (currency figure) in Col E of Sheet 1, keep it. The sheets could be of different row lengths.

    Can anyone out there help?

    Alan

  2. #2
    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 sh As Worksheet

    With Application

    .ScreenUpdating = False
    .Calculation = xlCalculationManual
    End With

    Set sh = Worksheets("Sheet2")
    With Worksheets("Sheet1")

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

    If Not IsError(Application.Match(.Cells(i, "A").Value, sh.Columns(1), 0)) Then

    If .Cells(i, "E").Value <> "" Then

    .Rows(i).Delete
    End If
    End If
    Next i
    End With

    With Application

    .Calculation = xlCalculationAutomatic
    .ScreenUpdating = True
    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

  3. #3
    Thanks xld. Do I copy and then paste the code into a Module?

  4. #4
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Yes, just cpy it into a standard code module, and run it from there.
    ____________________________________________
    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

Posting Permissions

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