From: JKWParrott on
I'm trying to figure out if I can set up a macro to delete rows if they do
not contain anything in specific columns.

For example, I have product codes in column A and totals for on-hand and
ordered numbers in columns B and C. If some rows do not have on-hand or
ordered numbers I want to delete those rows. Any ideas?
From: Ron de Bruin on
Start here
http://www.rondebruin.nl/delete.htm

For example in the first macro use
Change the range in this line that you want to test
If Application.CountA(.Cells(Lrow, 1).Range("A1,M1,X1")) = 0 Then .Rows(Lrow).Delete


Sub Loop_Example()
Dim Firstrow As Long
Dim Lastrow As Long
Dim Lrow As Long
Dim CalcMode As Long
Dim ViewMode As Long

With Application
CalcMode = .Calculation
.Calculation = xlCalculationManual
.ScreenUpdating = False
End With

'We use the ActiveSheet but you can replace this with
'Sheets("MySheet")if you want
With ActiveSheet

'We select the sheet so we can change the window view
.Select

'If you are in Page Break Preview Or Page Layout view go
'back to normal view, we do this for speed
ViewMode = ActiveWindow.View
ActiveWindow.View = xlNormalView

'Turn off Page Breaks, we do this for speed
.DisplayPageBreaks = False

'Set the first and last row to loop through
Firstrow = .UsedRange.Cells(1).Row
Lastrow = .UsedRange.Rows(.UsedRange.Rows.Count).Row

'We loop from Lastrow to Firstrow (bottom to top)
For Lrow = Lastrow To Firstrow Step -1

If Application.CountA(.Cells(Lrow, 1).Range("A1,M1,X1")) = 0 Then .Rows(Lrow).Delete
'This will delete the row if the cells in A, M and X in the row are empty

Next Lrow

End With

ActiveWindow.View = ViewMode
With Application
.ScreenUpdating = True
.Calculation = CalcMode
End With

End Sub


--

Regards Ron de Bruin
http://www.rondebruin.nl/tips.htm



"JKWParrott" <JKWParrott(a)discussions.microsoft.com> wrote in message news:E9D03181-6118-47C7-AE83-C99BAA5FD69A(a)microsoft.com...
> I'm trying to figure out if I can set up a macro to delete rows if they do
> not contain anything in specific columns.
>
> For example, I have product codes in column A and totals for on-hand and
> ordered numbers in columns B and C. If some rows do not have on-hand or
> ordered numbers I want to delete those rows. Any ideas?
From: Rick Rothstein on
> If some rows do not have on-hand or
> ordered numbers I want to delete those rows.

I note you said "or" and not "and" in the above, so I'm guessing that within
a given row, if either the cell in Column B **or** the cell in Column C (but
not necessarily both) are empty, then you want the entire row deleted. I'm
guessing the should work for you...

Sub DeleteUnneededRows()
On Error Resume Next
Columns("B:C").SpecialCells(xlCellTypeBlanks).EntireRow.Delete
End Sub

--
Rick (MVP - Excel)



"JKWParrott" <JKWParrott(a)discussions.microsoft.com> wrote in message
news:E9D03181-6118-47C7-AE83-C99BAA5FD69A(a)microsoft.com...
> I'm trying to figure out if I can set up a macro to delete rows if they do
> not contain anything in specific columns.
>
> For example, I have product codes in column A and totals for on-hand and
> ordered numbers in columns B and C. If some rows do not have on-hand or
> ordered numbers I want to delete those rows. Any ideas?

From: Ron de Bruin on
For The OP

If Rick's code do what you want be aware of this possible problem
http://www.rondebruin.nl/specialcells.htm

Have a nice day


--

Regards Ron de Bruin
http://www.rondebruin.nl/tips.htm



"Rick Rothstein" <rick.newsNO.SPAM(a)NO.SPAMverizon.net> wrote in message news:OqBY74v6KHA.1888(a)TK2MSFTNGP05.phx.gbl...
>> If some rows do not have on-hand or
>> ordered numbers I want to delete those rows.
>
> I note you said "or" and not "and" in the above, so I'm guessing that within
> a given row, if either the cell in Column B **or** the cell in Column C (but
> not necessarily both) are empty, then you want the entire row deleted. I'm
> guessing the should work for you...
>
> Sub DeleteUnneededRows()
> On Error Resume Next
> Columns("B:C").SpecialCells(xlCellTypeBlanks).EntireRow.Delete
> End Sub
>
> --
> Rick (MVP - Excel)
>
>
>
> "JKWParrott" <JKWParrott(a)discussions.microsoft.com> wrote in message
> news:E9D03181-6118-47C7-AE83-C99BAA5FD69A(a)microsoft.com...
>> I'm trying to figure out if I can set up a macro to delete rows if they do
>> not contain anything in specific columns.
>>
>> For example, I have product codes in column A and totals for on-hand and
>> ordered numbers in columns B and C. If some rows do not have on-hand or
>> ordered numbers I want to delete those rows. Any ideas?
>
From: JLGWhiz on
Thanks Ron, I was not aware of the xlSpecialCellsType limitation. Could
save me some grief in the future.


"Ron de Bruin" <rondebruin(a)kabelfoon.nl> wrote in message
news:OrGuj7v6KHA.3504(a)TK2MSFTNGP05.phx.gbl...
> For The OP
> If Rick's code do what you want be aware of this possible problem
> http://www.rondebruin.nl/specialcells.htm
>
> Have a nice day
>
>
> --
>
> Regards Ron de Bruin
> http://www.rondebruin.nl/tips.htm
>
>
>
> "Rick Rothstein" <rick.newsNO.SPAM(a)NO.SPAMverizon.net> wrote in message
> news:OqBY74v6KHA.1888(a)TK2MSFTNGP05.phx.gbl...
>>> If some rows do not have on-hand or
>>> ordered numbers I want to delete those rows.
>>
>> I note you said "or" and not "and" in the above, so I'm guessing that
>> within a given row, if either the cell in Column B **or** the cell in
>> Column C (but not necessarily both) are empty, then you want the entire
>> row deleted. I'm guessing the should work for you...
>>
>> Sub DeleteUnneededRows()
>> On Error Resume Next
>> Columns("B:C").SpecialCells(xlCellTypeBlanks).EntireRow.Delete
>> End Sub
>>
>> --
>> Rick (MVP - Excel)
>>
>>
>>
>> "JKWParrott" <JKWParrott(a)discussions.microsoft.com> wrote in message
>> news:E9D03181-6118-47C7-AE83-C99BAA5FD69A(a)microsoft.com...
>>> I'm trying to figure out if I can set up a macro to delete rows if they
>>> do
>>> not contain anything in specific columns.
>>>
>>> For example, I have product codes in column A and totals for on-hand and
>>> ordered numbers in columns B and C. If some rows do not have on-hand or
>>> ordered numbers I want to delete those rows. Any ideas?
>>