Computing.Net > Forums > Office Software > deleting a row in Excel 2000 macro

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

deleting a row in Excel 2000 macro

Reply to Message Icon

Name: halenhardy
Date: December 4, 2003 at 09:07:53 Pacific
OS: window me
CPU/Ram: pentium/128
Comment:

I want to sample a cell in Excel and if it is empty, I want to delete that row. I can delete a row using the row number but can't do it using a variable.
Example..
for row = 1 to 5
if activeheet.cells(row,3).value = "" then
rows(row:row).select 'range
selection.delete shift:= xlUp
end if
next row

This brings up a compiler error. If I use and actual row number than its ok. Any suggestions
Thanks..Gary



Sponsored Link
Ads by Google

Response Number 1
Name: Bryco
Date: December 4, 2003 at 16:37:41 Pacific
Reply:

The following works in Excel 97.

Before running the Macro you must select the range of cells within the column you are working with and then run the Macro.

Sub DeleteRowsBlank()
'
' DeleteRowsBlank Macro
' Macro recorded 12/04/2003
'

'
Selection.SpecialCells(xlCellTypeBlanks).Select
Selection.EntireRow.Delete
Range("A1").Select
End Sub


HTH
Bryan


0

Response Number 2
Name: safeTsurfa
Date: December 4, 2003 at 16:54:16 Pacific
Reply:

First, check your spelling in line 2! Then also read what compiler is telling you - you don't use a value:value for Row, it is a single reference (see line 3).

The below sample works:

For Row = 1 To 5
If ActiveSheet.Cells(Row, 3).Value = "" Then
Rows(Row).Delete shift:=xlUp
End If
Next Row


0

Response Number 3
Name: Gary Hardy
Date: December 5, 2003 at 16:24:49 Pacific
Reply:

Bryan.
Thanks. it did just what I was looking for. Now I have another question. How can I do the same thing looking for cells containing specific data such as "sold". I tried (xlcelltypecomments, "sold") but that didn't work. Thanks again..Gary


0

Response Number 4
Name: safeTsurfa
Date: December 5, 2003 at 22:11:14 Pacific
Reply:

I pass, Bryan can have this one. :)


0

Response Number 5
Name: Bryco
Date: December 6, 2003 at 05:37:15 Pacific
Reply:

If the only text string is "Sold" then you can use:

Sub DeleteRowsSold()
'
' DeleteRowsBlank Macro
' Macro recorded 12/04/2003
'

'
Selection.SpecialCells(xlCellTypeConstants, xlTextValues).Select
Selection.EntireRow.Delete
Range("A1").Select
End Sub

I am unable to specify just "Sold". (Lack of knowledge)

Bryan


0

Related Posts

See More



Response Number 6
Name: Bryco
Date: December 6, 2003 at 05:39:02 Pacific
Reply:

From Excel VBA Help:
Syntax

expression.SpecialCells(Type, Value)

expression Required. An expression that returns a Range object.

Type Required Long. The cells to include. Can be one of the following XlCellType constants.

Constant Description
xlCellTypeNotes Cells containing notes
xlCellTypeConstants Cells containing constants
xlCellTypeFormulas Cells containing formulas
xlCellTypeBlanks Empty cells
xlCellTypeLastCell The last cell in the used range
xlCellTypeVisible All visible cells
Value Optional Variant. If Type is either xlCellTypeConstants or xlCellTypeFormulas, this argument is used to determine which types of cells to include in the result. These values can be added together to return more than one type. The default is to select all constants or formulas, no matter what the type. Can be one of the following XlSpecialCellsValues constants: xlErrors, xlLogical, xlNumbers, xlTextValues, xlAllFormatConditions, or xlSameFormatConditions.


0

Response Number 7
Name: Brettster
Date: December 17, 2003 at 10:00:57 Pacific
Reply:

Hi

I'm trying to get Bryan's example to work for me but am having no luck. I need to search for the value 0 (Zero) in column B then delete the row that it is found on. Have tried typing in 'Selection.SpecialCells(xlCellTypeConstants, xlTextValues, "0").Select
andSelection.SpecialCells(xlCellTypeConstants, xlTextValues, 0).Select
but neither work. Please can someone help??

Thanks
Brett


0

Response Number 8
Name: Bryco
Date: December 17, 2003 at 13:39:29 Pacific
Reply:

A nice Add-on to Excel that has that feature is ASAP Utilities.

It is free.
The function can be found under:
Select, Conditional Row and Column Select, hide or delete.

HTH
Bryan


0

Sponsored Link
Ads by Google
Reply to Message Icon






Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Office Software Forum Home


Sponsored links

Ads by Google


Results for: deleting a row in Excel 2000 macro

Reverse rows in Excel 2003 www.computing.net/answers/office/reverse-rows-in-excel-2003/7798.html

Excel Formula Help - How to Delete a Row www.computing.net/answers/office/excel-formula-help-how-to-delete-a-row/9347.html

swap 2 rows in excel www.computing.net/answers/office/swap-2-rows-in-excel/8977.html