Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default Deleting rows

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?
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,123
Default Deleting rows

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" wrote in message ...
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?

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,934
Default Deleting rows

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).Enti reRow.Delete
End Sub

--
Rick (MVP - Excel)



"JKWParrott" wrote in message
...
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?


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,123
Default Deleting rows

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" wrote in message ...
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).Enti reRow.Delete
End Sub

--
Rick (MVP - Excel)



"JKWParrott" wrote in message
...
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?


  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,565
Default Deleting rows

Thanks Ron, I was not aware of the xlSpecialCellsType limitation. Could
save me some grief in the future.


"Ron de Bruin" wrote in message
...
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" wrote in message
...
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).Enti reRow.Delete
End Sub

--
Rick (MVP - Excel)



"JKWParrott" wrote in message
...
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
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Macro for deleting rows and serialising the remaing rows Srinivasulu Bhattaram Excel Programming 2 November 13th 08 01:32 PM
Macro for deleting rows and serialising the remaing rows Srinivasulu Bhattaram Links and Linking in Excel 1 November 13th 08 08:44 AM
Macro for deleting rows and serialising the remaing rows Srinivasulu Bhattaram Excel Worksheet Functions 1 November 12th 08 01:39 PM
Help!!! I have problem deleting 2500 rows of filtered rows shirley_kee[_2_] Excel Programming 1 January 12th 06 03:15 AM
deleting hidden rows so i can print only the rows showing?????? jenn Excel Worksheet Functions 0 October 6th 05 04:05 PM


All times are GMT +1. The time now is 10:20 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"