![]() |
![]() |
|
|||||||
| Excel Questions All Excel/VBA questions - formulas, macros, pivot tables, general help, etc. Please post to this forum in English only. |
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Guest
Posts: n/a
|
Does anyone have a VBA code that will look for a value of zero in say column P and delete the row containing this zero value?
I have three hundred spreadsheets of journal entries, but some of the journal lines have zero values so I can't upload those lines into our accounting software. This code would save me a tremendous amount of work. Thanks to any takers! Corey |
|
|
|
#2 |
|
MrExcel MVP
Join Date: Feb 2002
Location: Denver, Colorado USA
Posts: 4,014
|
The following macro will delete all rows containing any text you specify in column C. Hopefully it is obvious how to change it for other columns.
Sub DeleteZeroRows() ' This macro deletes all rows on the active worksheet ' that contain a zero value in column C. Dim iRow As Long For iRow = ActiveSheet.UsedRange.Rows.Count To 1 Step -1 If Cells(iRow, 3) = 0 Then Rows(iRow).Delete Next iRow End Sub
__________________
Keep Excelling. Damon VBAexpert Excel Consulting (My other life: http://damonostrander.com ) |
|
|
|
|
|
#3 | |
|
Guest
Posts: n/a
|
Quote:
Damon's macro is OK provided the first row on the worksheet that contains data is row 1. The following macro should work whatever the first row with data happens to be :- Sub DeleteZeroRows() Dim iRow As Long, firstRow As Long, lastRow As Long firstRow = ActiveSheet.UsedRange.Cells(1, 1).Row lastRow = Cells.SpecialCells(xlCellTypeLastCell).Row For iRow = lastRow To firstRow Step -1 If Cells(iRow, 3) = 0 Then Rows(iRow).Delete Next iRow End Sub |
|
|
![]() |
| Bookmarks |
| Thread Tools | |
| Display Modes | |
|
|