Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 63
Default Delete the contents of a cell if (REVISED)

If have simplified a problem I stated earlier:

If B1=1, delete the contents of A1. If B1 changes to any other value,
I do not want the former contents of A1 to return. Instead, I want to
be able to manually enter new contents, knowing that as often as B1
returns to equal 1, anything in A1 will be deleted. As I admit to my
novice status, the simpler the solution, the better. Thanks.

Michael

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 812
Default Delete the contents of a cell if (REVISED)

Add to worksheet module:

Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Address = "$B$1" And Target.Value = 1 Then Range("A1") =
""
'if A1 is changed and already B1=1, then A1 won't be deleted.
'you may want to enable the following line.
'If Target.Address = "$A$1" Then Range("B1") = ""
End Sub

Hth,
Merjet

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 63
Default Delete the contents of a cell if (REVISED)

Thanks Gary's Student and merjet for your suggestions. I'll be trying
both shortly and let you know shortly.

Michael

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 63
Default Delete the contents of a cell if (REVISED)

Gary's Student,

I have encountered 2 problems:

First, B1 has to equal something, so instead of nothing, can we
reformulate to make B1=0?

Second, I'm getting the message "Ambiguous name detected:
Worksheet_Change". does this have anything to do with the fact that
I have a different macro on the same worksheet labeled "Private Sub
Worksheet_Change(ByVal TargetCell As Range)", which is slightly
different from yours (you don't have "Cell" shown?

Michael

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 63
Default Delete the contents of a cell if (REVISED)

Gary's Student,

I have encountered 2 problems:

First, B1 has to equal something, so instead of nothing, can we
reformulate to make B1=0?

Second, I'm getting the message "Ambiguous name detected:
Worksheet_Change". does this have anything to do with the fact that
I have a different macro on the same worksheet labeled "Private Sub
Worksheet_Change(ByVal TargetCell As Range)", which is slightly
different from yours (you don't have "Cell" shown?

Michael



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 812
Default Delete the contents of a cell if (REVISED)

First, B1 has to equal something, so instead of nothing, can we
reformulate to make B1=0?


Yes, e.g.:
If Target.Address = "$A$1" Then Range("B1") = 0

Second, I'm getting the message "Ambiguous name detected:
Worksheet_Change". does this have anything to do with the fact that
I have a different macro on the same worksheet labeled "Private Sub
Worksheet_Change(ByVal TargetCell As Range)", which is slightly
different from yours (you don't have "Cell" shown?


Yes. You need to combine them, which is probably not a problem if
they have different "if conditions". Repace "TargetCell" with "Target"
in code before or after combining.

Hth,
Merjet

  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 63
Default Delete the contents of a cell if (REVISED)


Thanks merjet,

Unfortunately, when I make the suggested change, other existing
conditional macros no longer work. Thanks for trying, but this seems
to be beyond me for the time being.

Michael

  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10,124
Default Delete the contents of a cell if (REVISED)

Post ALL of your code here for comments and suggestions.

--
Don Guillett
SalesAid Software

wrote in message
ps.com...

Thanks merjet,

Unfortunately, when I make the suggested change, other existing
conditional macros no longer work. Thanks for trying, but this seems
to be beyond me for the time being.

Michael



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 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 Cell Contents IF joecrabtree Excel Programming 3 December 18th 06 02:21 PM
Delete all contents of cell but one word Hayette Hasham Excel Discussion (Misc queries) 5 January 18th 06 08:20 AM
Format excel to revised date automatically when revised annetteberrios Excel Programming 0 September 2nd 05 02:25 PM


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

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"