PC Review


Reply
Thread Tools Rate Thread

Clear Contents Of Cell If Value = 0 or Error

 
 
=?Utf-8?B?Y2FybA==?=
Guest
Posts: n/a
 
      9th Jul 2007
I posted last week on this problem I am trying to solve.


Sub stantiate()
Dim myRange As Range
Set myRange = Range("C10:d1000")
For Each c In myRange
If c.Value = 0 Then
c.Value = ""
End If
Next
End Sub

The code gets hung up at:

If c.Value = 0 Then

the cell value could be #N/A or some other
"errors".

Could this be the reason the code gets hung up ?

If so, is there a way to resolve the problem ?

Thank you in advance.
 
Reply With Quote
 
 
 
 
=?Utf-8?B?RS1Db2Rlcg==?=
Guest
Posts: n/a
 
      9th Jul 2007
If I'm understanding you correctly...if the cell value is actually a cell
error, you would like the cell value=0?

"carl" wrote:

> I posted last week on this problem I am trying to solve.
>
>
> Sub stantiate()
> Dim myRange As Range
> Set myRange = Range("C10:d1000")
> For Each c In myRange
> If c.Value = 0 Then
> c.Value = ""
> End If
> Next
> End Sub
>
> The code gets hung up at:
>
> If c.Value = 0 Then
>
> the cell value could be #N/A or some other
> "errors".
>
> Could this be the reason the code gets hung up ?
>
> If so, is there a way to resolve the problem ?
>
> Thank you in advance.

 
Reply With Quote
 
Susan
Guest
Posts: n/a
 
      9th Jul 2007
you haven't declared c..........

dim c as Range

blah blah
For Each c In myRange
If c.Value = 0 Then
c.Value = ""
End If
Next

also, "Next" needs to be "Next c"
you might also need to change
c.Value = ""
to
c.clearcontents

hope this helps!
susan


On Jul 9, 10:56 am, carl <c...@discussions.microsoft.com> wrote:
> I posted last week on this problem I am trying to solve.
>
> Sub stantiate()
> Dim myRange As Range
> Set myRange = Range("C10:d1000")
> For Each c In myRange
> If c.Value = 0 Then
> c.Value = ""
> End If
> Next
> End Sub
>
> The code gets hung up at:
>
> If c.Value = 0 Then
>
> the cell value could be #N/A or some other
> "errors".
>
> Could this be the reason the code gets hung up ?
>
> If so, is there a way to resolve the problem ?
>
> Thank you in advance.



 
Reply With Quote
 
=?Utf-8?B?Y2FybA==?=
Guest
Posts: n/a
 
      9th Jul 2007
Thanks for your help.

I need the contents of the cell cleared only if the value = 0.

That said, when I run the macro, some of the cells are #N\A and other error
messages.

I would like the macro to ignore the error messages.

"E-Coder" wrote:

> If I'm understanding you correctly...if the cell value is actually a cell
> error, you would like the cell value=0?
>
> "carl" wrote:
>
> > I posted last week on this problem I am trying to solve.
> >
> >
> > Sub stantiate()
> > Dim myRange As Range
> > Set myRange = Range("C10:d1000")
> > For Each c In myRange
> > If c.Value = 0 Then
> > c.Value = ""
> > End If
> > Next
> > End Sub
> >
> > The code gets hung up at:
> >
> > If c.Value = 0 Then
> >
> > the cell value could be #N/A or some other
> > "errors".
> >
> > Could this be the reason the code gets hung up ?
> >
> > If so, is there a way to resolve the problem ?
> >
> > Thank you in advance.

 
Reply With Quote
 
Rick Rothstein \(MVP - VB\)
Guest
Posts: n/a
 
      9th Jul 2007
Does this code do what you want?

Dim C As Range
Dim myRange As Range
Set myRange = Range("C10:d12")
For Each C In myRange
If Not IsError(C.Value) Then
If C.Value = 0 Then C.cl
End If
Next

Rick


"carl" <(E-Mail Removed)> wrote in message
news:8BCE2353-E52E-40A7-AB95-(E-Mail Removed)...
> Thanks for your help.
>
> I need the contents of the cell cleared only if the value = 0.
>
> That said, when I run the macro, some of the cells are #N\A and other
> error
> messages.
>
> I would like the macro to ignore the error messages.
>
> "E-Coder" wrote:
>
>> If I'm understanding you correctly...if the cell value is actually a cell
>> error, you would like the cell value=0?
>>
>> "carl" wrote:
>>
>> > I posted last week on this problem I am trying to solve.
>> >
>> >
>> > Sub stantiate()
>> > Dim myRange As Range
>> > Set myRange = Range("C10:d1000")
>> > For Each c In myRange
>> > If c.Value = 0 Then
>> > c.Value = ""
>> > End If
>> > Next
>> > End Sub
>> >
>> > The code gets hung up at:
>> >
>> > If c.Value = 0 Then
>> >
>> > the cell value could be #N/A or some other
>> > "errors".
>> >
>> > Could this be the reason the code gets hung up ?
>> >
>> > If so, is there a way to resolve the problem ?
>> >
>> > Thank you in advance.


 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Clear Cell Contents based on Criteria of another cell CK Microsoft Excel Programming 10 21st May 2009 04:07 PM
Macro to clear range contents when cell contents are changed by us =?Utf-8?B?U3RldmUgRQ==?= Microsoft Excel Programming 12 22nd Feb 2007 09:09 PM
Macro to Clear Cell Contents based on Cell Value in another Sheet CH Microsoft Excel Discussion 4 26th Jan 2007 08:37 PM
VBA Clear Cell Contents towl Microsoft Excel Programming 4 20th Oct 2005 05:14 PM
Type into one cell and automatically clear contents in another cell Bo Microsoft Excel Programming 4 29th Sep 2003 06:04 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 01:30 PM.