PC Review


Reply
Thread Tools Rate Thread

Deleting rows

 
 
JKWParrott
Guest
Posts: n/a
 
      3rd May 2010
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?
 
Reply With Quote
 
 
 
 
Ron de Bruin
Guest
Posts: n/a
 
      3rd May 2010
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" <(E-Mail Removed)> wrote in message news:E9D03181-6118-47C7-AE83-(E-Mail Removed)...
> 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?

 
Reply With Quote
 
Rick Rothstein
Guest
Posts: n/a
 
      3rd May 2010
> 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" <(E-Mail Removed)> wrote in message
news:E9D03181-6118-47C7-AE83-(E-Mail Removed)...
> 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?


 
Reply With Quote
 
Ron de Bruin
Guest
Posts: n/a
 
      3rd May 2010
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" <(E-Mail Removed)> wrote in message news:(E-Mail Removed)...
>> 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" <(E-Mail Removed)> wrote in message
> news:E9D03181-6118-47C7-AE83-(E-Mail Removed)...
>> 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?

>

 
Reply With Quote
 
JLGWhiz
Guest
Posts: n/a
 
      4th May 2010
Thanks Ron, I was not aware of the xlSpecialCellsType limitation. Could
save me some grief in the future.


"Ron de Bruin" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
>>> 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" <(E-Mail Removed)> wrote in message
>> news:E9D03181-6118-47C7-AE83-(E-Mail Removed)...
>>> 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?

>>



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
deleting blank rows for up to 60000 rows of data gbpg Microsoft Excel Programming 3 27th Dec 2009 08:37 PM
Macro for deleting rows and serialising the remaing rows Srinivasulu Bhattaram Microsoft Excel Programming 2 13th Nov 2008 01:32 PM
Macro for deleting rows and serialising the remaing rows Srinivasulu Bhattaram Microsoft Excel Worksheet Functions 1 12th Nov 2008 01:39 PM
Macro for deleting rows and serialising the remaing rows Srinivasulu Bhattaram Microsoft Excel Discussion 1 12th Nov 2008 01:32 PM
Excel 2000 VBA Deleting Rows when certain text in rows exists scain2004 Microsoft Excel New Users 1 15th Mar 2004 02:11 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 07:29 PM.