Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 3
Default Delete the contents of a cell if it contains #DIV/0! Automaticall.

I am building an execl sheet that holds production data. Some pieces of
equipment only run occasionally and because of this they cause a #DIV/0!
error. I want to be able to look through the complete range (a1:di54) of
cells and whenver I find the error i want to delete the contents of the cell.
I guess this is possible to do using a Visual Basic module but my experience
of Visual Basic is limited.
  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 8,520
Default Delete the contents of a cell if it contains #DIV/0! Automaticall.

Its better to handle the error within the formula itself.

If =A1/B1 returns an error change the formula to

=IF(N(B1),A1/B1,"")


You can try out the below macro. If you are new to macros..

--Set the Security level to low/medium in (Tools|Macro|Security).
--From workbook launch VBE using short-key Alt+F11.
--From menu 'Insert' a module and paste the below code.
--Get back to Workbook.
--Run macro from Tools|Macro|Run <selected macro()


Sub Macro()
Dim cell As Range
For Each cell In ActiveSheet.UsedRange
If cell.Text = "#DIV/0!" Then cell.ClearContents
Next
End Sub


--
Jacob (MVP - Excel)


"GoodyA10" wrote:

I am building an execl sheet that holds production data. Some pieces of
equipment only run occasionally and because of this they cause a #DIV/0!
error. I want to be able to look through the complete range (a1:di54) of
cells and whenver I find the error i want to delete the contents of the cell.
I guess this is possible to do using a Visual Basic module but my experience
of Visual Basic is limited.

  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 11,058
Default Delete the contents of a cell if it contains #DIV/0! Automaticall.

Try this simple macro:

Sub ClearErrors()
Dim r As Range
Set r = Range("A1:DI54").Cells.SpecialCells(xlCellTypeForm ulas, xlErrors)
r.Clear
End Sub



Macros are very easy to install and use:

1. ALT-F11 brings up the VBE window
2. ALT-I
ALT-M opens a fresh module
3. paste the stuff in and close the VBE window

If you save the workbook, the macro will be saved with it.

To remove the macro:

1. bring up the VBE window as above
2. clear the code out
3. close the VBE window

To use the macro from Excel:

1. ALT-F8
2. Select the macro
3. Touch RUN

To learn more about macros in general, see:

http://www.mvps.org/dmcritchie/excel/getstarted.htm

--
Gary''s Student - gsnu201001


"GoodyA10" wrote:

I am building an execl sheet that holds production data. Some pieces of
equipment only run occasionally and because of this they cause a #DIV/0!
error. I want to be able to look through the complete range (a1:di54) of
cells and whenver I find the error i want to delete the contents of the cell.
I guess this is possible to do using a Visual Basic module but my experience
of Visual Basic is limited.

  #4   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 3
Default Delete the contents of a cell if it contains #DIV/0! Automatic

Thanks for that both solutions did the trick.

Cheers

"Jacob Skaria" wrote:

Its better to handle the error within the formula itself.

If =A1/B1 returns an error change the formula to

=IF(N(B1),A1/B1,"")


You can try out the below macro. If you are new to macros..

--Set the Security level to low/medium in (Tools|Macro|Security).
--From workbook launch VBE using short-key Alt+F11.
--From menu 'Insert' a module and paste the below code.
--Get back to Workbook.
--Run macro from Tools|Macro|Run <selected macro()


Sub Macro()
Dim cell As Range
For Each cell In ActiveSheet.UsedRange
If cell.Text = "#DIV/0!" Then cell.ClearContents
Next
End Sub


--
Jacob (MVP - Excel)


"GoodyA10" wrote:

I am building an execl sheet that holds production data. Some pieces of
equipment only run occasionally and because of this they cause a #DIV/0!
error. I want to be able to look through the complete range (a1:di54) of
cells and whenver I find the error i want to delete the contents of the cell.
I guess this is possible to do using a Visual Basic module but my experience
of Visual Basic is limited.

  #5   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 3
Default Delete the contents of a cell if it contains #DIV/0! Automatic

Thanks for the reply



"Gary''s Student" wrote:

Try this simple macro:

Sub ClearErrors()
Dim r As Range
Set r = Range("A1:DI54").Cells.SpecialCells(xlCellTypeForm ulas, xlErrors)
r.Clear
End Sub



Macros are very easy to install and use:

1. ALT-F11 brings up the VBE window
2. ALT-I
ALT-M opens a fresh module
3. paste the stuff in and close the VBE window

If you save the workbook, the macro will be saved with it.

To remove the macro:

1. bring up the VBE window as above
2. clear the code out
3. close the VBE window

To use the macro from Excel:

1. ALT-F8
2. Select the macro
3. Touch RUN

To learn more about macros in general, see:

http://www.mvps.org/dmcritchie/excel/getstarted.htm

--
Gary''s Student - gsnu201001


"GoodyA10" wrote:

I am building an execl sheet that holds production data. Some pieces of
equipment only run occasionally and because of this they cause a #DIV/0!
error. I want to be able to look through the complete range (a1:di54) of
cells and whenver I find the error i want to delete the contents of the cell.
I guess this is possible to do using a Visual Basic module but my experience
of Visual Basic is limited.

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
Delete ROW based on Cell Contents HeatherJ Excel Discussion (Misc queries) 4 February 11th 10 04:25 PM
delete contents of cell RDC Excel Discussion (Misc queries) 1 January 21st 09 04:13 PM
Delete cell contents Rob[_4_] Excel Discussion (Misc queries) 7 April 10th 07 12:34 PM
Delete all contents of cell but one word Hayette Hasham Excel Discussion (Misc queries) 5 January 18th 06 08:20 AM
Delete row based on contents of cell AndyG Excel Discussion (Misc queries) 6 November 17th 05 10:08 PM


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

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

About Us

"It's about Microsoft Excel"