Consulting

Results 1 to 3 of 3

Thread: Deleting rows based on values of cells in TWO different columns

  1. #1
    VBAX Newbie
    Joined
    Jul 2016
    Posts
    2
    Location

    Deleting rows based on values of cells in TWO different columns

    Hi there, I am looking to delete rows that do not contain "ECB account of monetary policy meeting" in column E and contain the value zero in column F. I.e if the value in column E is equal to "ECB account of monetary policy meeting" and column F is equal to 0 then keep - however if column E does not contain "ECB account...." and column F is equal to 0 then delete all rows where this is true. This is the code I'm using but it is just deleting every row where column F = 0, including the rows where cells in row E contain the ECB value



    'Get the last row and column B
    finalRow = Cells(1000, 2).End(xlUp).row
    'Loop through data backwards
    For i = finalRow To 1 Step -1
      'Do your check
      If (Cells(i, 5) <> "ECB account of monetary policy meeting" And Cells(i, 6) = 0) Then
        'Delete the row if criteria met
        Cells(i, 1).EntireRow.Delete
      End If
      Next i

  2. #2
    Administrator
    VP-Knowledge Base
    VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    Try
      If Trim((Cells(i, 5)) <> "ECB account of monetary policy meeting" And Cells(i, 6) = 0) Then
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  3. #3
    VBAX Newbie
    Joined
    Jul 2016
    Posts
    2
    Location
    That worked perfect thanks!

Tags for this Thread

Posting Permissions

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