Home |
Search |
Today's Posts |
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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 |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Macro for deleting rows and serialising the remaing rows | Excel Programming | |||
Macro for deleting rows and serialising the remaing rows | Links and Linking in Excel | |||
Macro for deleting rows and serialising the remaing rows | Excel Worksheet Functions | |||
Help!!! I have problem deleting 2500 rows of filtered rows | Excel Programming | |||
deleting hidden rows so i can print only the rows showing?????? | Excel Worksheet Functions |