Solved

Delete criteria change to code

Posted on 2013-05-29
5
199 Views
Last Modified: 2013-05-29
Is there a way to add to the delete portion of the code an exception "not to delete the row on the Accounts tab where the word "Manual" is in column B".

somehow this this row    "If Not (IsEmpty(Sheets("Compare").Cells(objCell.Row, "AP"))) Then
               Sheets("Accounts").Rows(lngRow).EntireRow.Delete

Thanks in advance.
________________________________________________________________

Sub DeleteMissingAccounts()

  Dim lngRow                                            As Long
  Dim objCell                                           As Range
  Dim objRange                                          As Range
 
  On Error Resume Next
    Application.ScreenUpdating = False
 
   Set objRange = Range(Sheets("Compare").[c3], Sheets("Compare").Cells(Sheets("Compare").Cells.Rows.Count, "C").End(xlUp))
 
 If Not (objRange Is Nothing) Then
     Sheets("Accounts").Select
 
     For lngRow = Cells(Cells.Rows.Count, 1).End(xlUp).Row To 2& Step -1&
 
         Set objCell = Nothing
         Set objCell = objRange.Find(What:=Cells(lngRow, "A"))
     
         If Not (objCell Is Nothing) Then
            If Not (IsEmpty(Sheets("Compare").Cells(objCell.Row, "AP"))) Then
               Sheets("Accounts").Rows(lngRow).EntireRow.Delete
            End If
         End If        
     Next lngRow
     
 End If ' If Not (objRange Is Nothing) Then
0
Comment
Question by:leezac
  • 3
  • 2
5 Comments
 
LVL 40

Expert Comment

by:als315
ID: 39205447
Change
If Not (IsEmpty(Sheets("Compare").Cells(objCell.Row, "AP"))) Then
to:
If (Sheets("Compare").Cells(objCell.Row, "B") <> "Manual") And (Not (IsEmpty(Sheets("Compare").Cells(objCell.Row, "AP")))) Then

Open in new window

0
 

Author Comment

by:leezac
ID: 39205516
Thanks,  I just thought - can I put <> "Manual" or "Duplicate")
in this line?

If (Sheets("Compare").Cells(objCell.Row, "B") <> "Manual")
0
 
LVL 40

Accepted Solution

by:
als315 earned 500 total points
ID: 39205528
You can add both criterias:
If (Sheets("Compare").Cells(objCell.Row, "B") <> "Manual") AND (Sheets("Compare").Cells(objCell.Row, "B") <> "Duplicate")

Open in new window

0
 

Author Comment

by:leezac
ID: 39205532
als315 that does not work

If "Manual" is in Column B  of the Accounts tab (has nothing to do with the Compare tab) I just want to be able to keep it and not delete it when the other rows are deleted.
0
 

Author Closing Comment

by:leezac
ID: 39205884
These were answers that would work, but I need to repost the question.
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A little background as to how I came to I design this code: Around 5 years ago I designed an add-in that formatted Excel files to a corporate standard, applying different cell colours and font type depending on whether the cells contained inputs,…
When you see single cell contains number and text, and you have to get any date out of it seems like cracking our heads.
The viewer will learn how to use a discrete random variable to simulate the return on an investment over a period of years, create a Monte Carlo simulation using the discrete random variable, and create a graph to represent the possible returns over…
This Micro Tutorial will demonstrate on a Mac how to change the sort order for chart legend values and decrpyt the intimidating chart menu.

856 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question