Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Excel / Programming / January 2007

Tip: Looking for answers? Try searching our database.

Delete the contents of a cell under multiple conditions

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
mrlanier@hotmail.com - 22 Jan 2007 17:30 GMT
If cell A1=1, A1=3 or A1=5, I want the existing contents of B1 to be
deleted.  However, if A1=2 or A1=4, I want to be able to enter input
into B1.  Can someone suggest a macro for this?  Thanks.

Michael
okrob - 22 Jan 2007 19:02 GMT
Try this:
Public Sub test()
Dim Cvalue As Double
Cvalue = Range("A1").Value
  On Error GoTo test_Error
   Select Case Cvalue
       Case 1
           Range("B1").ClearContents
       Case 2
           Range("B1").Value = Application.InputBox("Input value for
B1")
       Case 3
           Range("B1").ClearContents
       Case 4
           Range("B1").Value = Application.InputBox("Input value for
B1")
       Case Else
       Exit Sub
   End Select
On Error GoTo 0
  Exit Sub

test_Error:
   MsgBox "Error " & Err.Number & " (" & Err.Description & ") in
procedure test of Module Module1"
End Sub

Rob

> If cell A1=1, A1=3 or A1=5, I want the existing contents of B1 to be
> deleted.  However, if A1=2 or A1=4, I want to be able to enter input
> into B1.  Can someone suggest a macro for this?  Thanks.
>
> Michael
mrlanier@hotmail.com - 22 Jan 2007 19:18 GMT
Thanks Gary's Studuent and Rob,

It looks like I've got 2 promising possibilities.  However, as a
novice, I'm a little confused over someting you both have indicated.
In both solutions, I need to enter a value for B1.  What I need to
reflect is any value greater than 0.  How specifically would I state
this?  Rather, how would it appear?  Thanks again.

Michael
okrob - 22 Jan 2007 21:48 GMT
Your original post:
---------------------------------
If cell A1=1, A1=3 or A1=5, I want the existing contents of B1 to be
deleted.  However, if A1=2 or A1=4, I want to be able to enter input
into B1.  Can someone suggest a macro for this?  Thanks.

Michael
---------------------------------

It looked to me like you wanted the user to be prompted to input a
value for B1.  If this is not the case, what exactly do you want the
cell in B1 to do if A1 is 2 or 4?

Basically, if the value for B1 doesn't matter, you can just delete this
line from Gary''s Student's code:
Range("B1").Value = Application.InputBox("Enter a value for B1:")

> Thanks Gary's Studuent and Rob,
>
[quoted text clipped - 5 lines]
>
> Michael
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.