Solved

EXCEL Macro to Delete Row

Posted on 2016-08-16
6
54 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:Wass_QA
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
Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

 
LVL 45

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 28

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:Wass_QA
ID: 41758378
Super,
Merci, Thank you.
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Using Word 2013, I was experiencing some incredible lag when typing.  Here's what worked for me....
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
This Micro Tutorial will demonstrate how to use longer labels with horizontal bar charts instead of the vertical column chart.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

707 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now