ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   macro to delete certain results (https://www.excelbanter.com/excel-programming/413347-macro-delete-certain-results.html)

DFrank

macro to delete certain results
 
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.


Jarek Kujawa[_2_]

macro to delete certain results
 
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

Jarek Kujawa[_2_]

macro to delete certain results
 
forgot about "End Sub" after "Next cell"

sorry

DFrank

macro to delete certain results
 
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.

"Jarek Kujawa" wrote:

forgot about "End Sub" after "Next cell"

sorry


Jarek Kujawa[_2_]

macro to delete certain results
 
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

Jarek Kujawa[_2_]

macro to delete certain results
 
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

DFrank

macro to delete certain results
 
something isnt lining up with the paste. here is a picture of what happens, i
cant seem to get it aligned properly. here is my macro:

http://img119.imageshack.us/img119/8384/macromb4.jpg


also, the selection is the whole worksheet, so maybe that part of the code
needs modified? im not sure, im not so good with this macro business.

"Jarek Kujawa" wrote:

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


DFrank

macro to delete certain results
 
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.

"Jarek Kujawa" wrote:

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


Jarek Kujawa[_2_]

macro to delete certain results
 
should be

DFrank

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

"Jarek Kujawa" wrote:

should be



All times are GMT +1. The time now is 08:55 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com