macro to delete certain results

D

DFrank

I am making a macro that deletes #N/A's, but i want to add a few things to it
that should be deleted:

the phrases "total board" and "total metal", and any non-text (i.e. any
number) that appears.

this is what i have so far:

Public Sub DeleteStuff()
Cells.SpecialCells(xlCellTypeFormulas, xlErrors).Delete
End Sub



what do i add to meet my specifications? thanks.
 
J

Jarek Kujawa

yr macro will delete ALL cells with errors and formulas that are in
the worksheet

to remove "total board" and "total metal" and numeric values select yr
data and use:

Sub deletstuff2()
For Each cell in Selection
If cell = ""total board" or cell = "total metal" or IsNumeric(cell)
Then
cell.Delete
End If
Next cell
 
D

DFrank

Thanks for the reply. Im sure this will help. for simplification purposes, i
want to add it to the already existing macro. this is what it looks like:

Public Sub DeleteStuff()
Cells.SpecialCells(xlCellTypeFormulas, xlErrors).Delete

For Each cell In Selection
If cell = ""total board" or cell = "total metal" or IsNumeric(cell)
Then
cell.Delete
End If

Next cell

End Sub


this gives me an error. what is wrong? thanks.
 
J

Jarek Kujawa

probably you didn't select an area with "total board" etc.
besides "Then" must be in the same line as "If" (the browser wrapped
it incorrectly)

try this version

Public Sub DeleteStuff()

For Each cell In Selection
If cell = ""total board" or cell = "total metal" or
IsNumeric(cell) or cell.HasFormula or IsError(Cell) Then
cell.Delete
End If

Next cell


End Sub


this macro will delete ONLY cells (fulfilling conditions) in the
SELECTED AREA
 
J

Jarek Kujawa

the browser wrapped it incorrectly AGAIN



Public Sub DeleteStuff()

For Each cell In Selection
If cell = ""total board" or cell = "total metal" _
or IsNumeric(cell) or cell.HasFormula _
or IsError(Cell) Then
cell.Delete
End If
Next cell

End Sub

this should work well
 
D

DFrank

Ok thanks, but for some reason ITEM and zeros still appear. i changed the
code to this:

For Each Cell In Selection
If Cell = "total board" Or Cell = "total metal" Or Cell = "ITEM" Or Cell
= "0" _
Or IsNumeric(Cell) Or Cell.HasFormula _
Or IsError(Cell) Then
Cell.Delete
End If
Next Cell



is that right? thanks.
 
D

DFrank

thanks. it still isnt working for some reason. i made a new topic towards the
top since this one is getting kind of cluttered.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top