Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
Bo Bo is offline
external usenet poster
 
Posts: 2
Default Type into one cell and automatically clear contents in another cell

Is there a way to type information into a cell and have visual basic
clear the contents in another cell without clicking on a button etc?

cell A1 cell B1
..595 .42 (.42 would be deleted by typing .595 in cell A1)

Or the contents in cell A1 would be deleted if Cell B1 value changes
or is greater than 0.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 23
Default Type into one cell and automatically clear contents in another cell

Try something like this using the Change event of the Worksheet object:

Private Sub Worksheet_Change(ByVal Target As Range)
If Target.AddressLocal = Range("A1").AddressLocal Then
Range("B1").ClearContents
End If
End Sub


Bill Barclift

"Bo" wrote in message
m...
Is there a way to type information into a cell and have visual basic
clear the contents in another cell without clicking on a button etc?

cell A1 cell B1
.595 .42 (.42 would be deleted by typing .595 in cell A1)

Or the contents in cell A1 would be deleted if Cell B1 value changes
or is greater than 0.



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,089
Default Type into one cell and automatically clear contents in another cell

Bo

try something along these lines:

' Sheet1 Class Module

Private Sub Worksheet_Change(ByVal Target As Range)
' specific check on cells A1 and B1
If Intersect(Target, Range("A1:B1")) Is Nothing Then Exit Sub
Application.EnableEvents = False
Select Case Target.Address(False, False)
Case "A1": Range("B1").Value = ""
Case "B1": Range("A1").Value = ""
End Select
Application.EnableEvents = True
End Sub

Or ...

Private Sub Worksheet_Change(ByVal Target As Range)
' check columns A and B
If Intersect(Target, Range("A:B")) Is Nothing Then Exit Sub
Application.EnableEvents = False
Select Case Left(Target.Address(False, False), 1)
Case "A": Target.Offset(0, 1).Value = ""
Case "B": Target.Offset(0, -1).Value = ""
End Select
Application.EnableEvents = True
End Sub

You might need to check for specifics like greater than 0

Regards

Trevor


"Bo" wrote in message
m...
Is there a way to type information into a cell and have visual basic
clear the contents in another cell without clicking on a button etc?

cell A1 cell B1
.595 .42 (.42 would be deleted by typing .595 in cell A1)

Or the contents in cell A1 would be deleted if Cell B1 value changes
or is greater than 0.



  #4   Report Post  
Posted to microsoft.public.excel.programming
Bo Bo is offline
external usenet poster
 
Posts: 2
Default Type into one cell and automatically clear contents in another cell

Bill:
Thank you for the response to my question. The code works very good
but has a minor problem. If cell a1 changes it will delete the
contents in cell b1 which works fine. But when I add code for b1
(typing in a value will delete the contents in cell a1) is where the
problem comes in. It works but when cell a1 contents is deleted it
activates the code again and clears the contents in cell b1. Typing in
either cell will completely delete information in both cells. Hope you
have a fix for this.

Private Sub Worksheet_Change(ByVal Target As Range)
If Target.AddressLocal = Range("A1").AddressLocal Then
Range("B1").ClearContents
End If
If Target.AddressLocal = Range("b1").AddressLocal Then
Range("a1").ClearContents
End If
End Sub



Thank you for your help....


"Bill Barclift" wrote in message . ..
Try something like this using the Change event of the Worksheet object:

Private Sub Worksheet_Change(ByVal Target As Range)
If Target.AddressLocal = Range("A1").AddressLocal Then
Range("B1").ClearContents
End If
End Sub


Bill Barclift

"Bo" wrote in message
m...
Is there a way to type information into a cell and have visual basic
clear the contents in another cell without clicking on a button etc?

cell A1 cell B1
.595 .42 (.42 would be deleted by typing .595 in cell A1)

Or the contents in cell A1 would be deleted if Cell B1 value changes
or is greater than 0

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,089
Default Type into one cell and automatically clear contents in another cell

Bo

You need:

Application.EnableEvents = False
'your code
Application.EnableEvents = True


why not try the solutions I posted on the 26/09/03:


try something along these lines:

' Sheet1 Class Module

Private Sub Worksheet_Change(ByVal Target As Range)
' specific check on cells A1 and B1
If Intersect(Target, Range("A1:B1")) Is Nothing Then Exit Sub
Application.EnableEvents = False
Select Case Target.Address(False, False)
Case "A1": Range("B1").Value = ""
Case "B1": Range("A1").Value = ""
End Select
Application.EnableEvents = True
End Sub

Or ...

Private Sub Worksheet_Change(ByVal Target As Range)
' check columns A and B
If Intersect(Target, Range("A:B")) Is Nothing Then Exit Sub
Application.EnableEvents = False
Select Case Left(Target.Address(False, False), 1)
Case "A": Target.Offset(0, 1).Value = ""
Case "B": Target.Offset(0, -1).Value = ""
End Select
Application.EnableEvents = True
End Sub

You might need to check for specifics like greater than 0

Regards

Trevor


"Bo" wrote in message
om...
Bill:
Thank you for the response to my question. The code works very good
but has a minor problem. If cell a1 changes it will delete the
contents in cell b1 which works fine. But when I add code for b1
(typing in a value will delete the contents in cell a1) is where the
problem comes in. It works but when cell a1 contents is deleted it
activates the code again and clears the contents in cell b1. Typing in
either cell will completely delete information in both cells. Hope you
have a fix for this.

Private Sub Worksheet_Change(ByVal Target As Range)
If Target.AddressLocal = Range("A1").AddressLocal Then
Range("B1").ClearContents
End If
If Target.AddressLocal = Range("b1").AddressLocal Then
Range("a1").ClearContents
End If
End Sub



Thank you for your help....


"Bill Barclift" wrote in message

. ..
Try something like this using the Change event of the Worksheet object:

Private Sub Worksheet_Change(ByVal Target As Range)
If Target.AddressLocal = Range("A1").AddressLocal Then
Range("B1").ClearContents
End If
End Sub


Bill Barclift

"Bo" wrote in message
m...
Is there a way to type information into a cell and have visual basic
clear the contents in another cell without clicking on a button etc?

cell A1 cell B1
.595 .42 (.42 would be deleted by typing .595 in cell A1)

Or the contents in cell A1 would be deleted if Cell B1 value changes
or is greater than 0



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
How do I clear a cell contents but not the formula behind it SliderSteve Excel Discussion (Misc queries) 5 November 19th 07 11:33 PM
Clear Contents Of Cell If Value = 0 or Error carl Excel Worksheet Functions 4 July 9th 07 04:54 PM
Is there a formula to clear the contents of a specific cell? Bob Smith Excel Worksheet Functions 2 December 9th 06 07:41 PM
vb to clear cell contents RichT New Users to Excel 6 June 27th 05 08:26 AM
Clear cell contents with a button KFC / A&W Boy Excel Worksheet Functions 1 March 7th 05 09:39 AM


All times are GMT +1. The time now is 03:44 PM.

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

About Us

"It's about Microsoft Excel"