Solved

EXCEL Macro to Delete Row

Posted on 2016-08-16
6
62 Views
Last Modified: 2016-08-16
Hello,
can you please help with a macro,
Delete Rows,
if Column "D" duplicates, and if Column "K" value is 0$ and there is another value in column 'K"
then Delete Row with 0$.

if Column "D" duplicates , and the value in Column "K" IS 0$ and there is NO another value in column 'K", then , do not delete row.

if no duplicates in Column "D", then do nothing.

Attached is ample, before, after

I have about 4000- 5000 in each column
Your help is appreciated,
Sample.xlsx
0
Comment
Question by:W.E.B
6 Comments
 
LVL 2

Accepted Solution

by:
Martin Andrews earned 500 total points
ID: 41758342
Here you go.  It removes the duplicate zero entries that you had in your desired output, though, which I think is what you actually want.
Sample2.xlsm
0
 
LVL 2

Expert Comment

by:Martin Andrews
ID: 41758350
You just need to click on the Macros button in the Developer tab and run the cleanup script
0
 
LVL 2

Expert Comment

by:Martin Andrews
ID: 41758355
If you can't see the Developer tab, click on the File menu and then select Options from the drop down menu. When the Excel Options window appears, click on the Customize Ribbon option on the left. Click on the Developer checkbox under the list of Main Tabs on the right. Then click on the OK button
0
What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

 
LVL 46

Expert Comment

by:Martin Liss
ID: 41758360
In case you need them, here are instructions on how to install and use a macro.

In Excel, Press Alt+F11 to open the Visual Basic Editor (VBE)

Right-click on your workbook name in the "Project-VBAProject" pane (at the top left corner of the editor window). If you don’t see an existing module then select Insert -> Module from the context menu. Otherwise just select the module.

Copy the macro (you can use the ‘Select All’ button if you like) and paste it into the right-hand pane of the VBA editor ("Module1" window)

Press Alt+F11 again to go back to Excel

Optionally, press Alt+F8 to open the "Macro" dialog window. Select the macro, click ‘Options…’,  hold down the Shift key and type the letter A (or any other letter) and click ‘OK’. Then anytime you want to run the macro press Ctrl+Shift+A.

When you close the workbook you will need to save it as an xlsm or xls file if it’s not already one of those.
0
 
LVL 29

Expert Comment

by:Subodh Tiwari (Neeraj)
ID: 41758370
Please try this.....

Sub DeleteRows()
Dim lr As Long
Application.ScreenUpdating = False
lr = Cells(Rows.Count, 4).End(xlUp).Row
Columns(12).Insert
Range("L2:L" & lr).Formula = "=IF(AND(COUNTIF($D$2:$D$" & lr & ",D2)>1,SUMIF($D$2:$D$" & lr & ",D2,$K$2:$K$" & lr & ")>0,K2=0),1,"""")"
On Error Resume Next
Range("L2:L" & lr).SpecialCells(xlCellTypeFormulas, 1).EntireRow.Delete
Columns(12).Delete
Application.ScreenUpdating = True
End Sub

Open in new window

0
 

Author Closing Comment

by:W.E.B
ID: 41758378
Super,
Merci, Thank you.
0

Featured Post

Is Your AD Toolbox Looking More Like a Toybox?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

Question has a verified solution.

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

Recently Microsoft released a brand new function called CONCAT. It's supposed to replace its predecessor CONCATENATE. But how does it work? And what's new? In this article, we take a closer look at all of this - we even included an exercise file for…
In this article we discuss how to recover the missing Outlook 2011 for Mac data like Emails and Contacts manually.
This Micro Tutorial will demonstrate in Google Sheets how to use the HYPERLINK function to create live links inside your spreadsheet.
This Micro Tutorial will demonstrate in Microsoft Excel how to add style and sexy appeal to horizontal bar charts.

831 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