Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 557
Default Clear Contents of Offset cells automatically

Hi all, I got macro below which automatically put figures in Offset
cells when I put any figure in Target cell. It works fine but I want
that when I Clear Contents of Target cell by pressing Delete button on
Keyboard then Contents of Offset cells should also be cleared
automatically. Please can any friend can help

Private Sub Worksheet_Change(ByVal Target As Range)
On Error GoTo Whoops
Application.EnableEvents = False
If Not Intersect(Target, Range("A2:A5")) Is Nothing Then
Target.Offset(, 1) = Target * 52
Target.Offset(, 2) = Target * 12
Else
End If
Whoops:
Application.EnableEvents = True
End Sub
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,501
Default Clear Contents of Offset cells automatically

Hi,

Try this

Private Sub Worksheet_Change(ByVal Target As Range)
On Error GoTo Whoops
Application.EnableEvents = False
If Not Intersect(Target, Range("A2:A5")) Is Nothing Then
If Len(Target.Value) 0 Then
Target.Offset(, 1) = Target * 52
Target.Offset(, 2) = Target * 12
Else
Target.Offset(, 1).ClearContents
Target.Offset(, 2).ClearContents
End If
End If
Whoops:
Application.EnableEvents = True
End Sub

Mike

"K" wrote:

Hi all, I got macro below which automatically put figures in Offset
cells when I put any figure in Target cell. It works fine but I want
that when I Clear Contents of Target cell by pressing Delete button on
Keyboard then Contents of Offset cells should also be cleared
automatically. Please can any friend can help

Private Sub Worksheet_Change(ByVal Target As Range)
On Error GoTo Whoops
Application.EnableEvents = False
If Not Intersect(Target, Range("A2:A5")) Is Nothing Then
Target.Offset(, 1) = Target * 52
Target.Offset(, 2) = Target * 12
Else
End If
Whoops:
Application.EnableEvents = True
End Sub

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,533
Default Clear Contents of Offset cells automatically

Hi

Try this:

Private Sub Worksheet_Change(ByVal Target As Range)
On Error GoTo Whoops
If Not Intersect(Target, Range("A2:A5")) Is Nothing Then
Application.EnableEvents = False
If Target.Value < "" Then
Target.Offset(, 1) = Target * 52
Target.Offset(, 2) = Target * 12
Else
Target.Offset(, 1) = ""
Target.Offset(, 2) = ""
End If
End If
Whoops:
Application.EnableEvents = True
End Sub

Regards,
Per

"K" skrev i meddelelsen
...
Hi all, I got macro below which automatically put figures in Offset
cells when I put any figure in Target cell. It works fine but I want
that when I Clear Contents of Target cell by pressing Delete button on
Keyboard then Contents of Offset cells should also be cleared
automatically. Please can any friend can help

Private Sub Worksheet_Change(ByVal Target As Range)
On Error GoTo Whoops
Application.EnableEvents = False
If Not Intersect(Target, Range("A2:A5")) Is Nothing Then
Target.Offset(, 1) = Target * 52
Target.Offset(, 2) = Target * 12
Else
End If
Whoops:
Application.EnableEvents = True
End Sub


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 557
Default Clear Contents of Offset cells automatically

thanks lot guys

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
Clear contents of cells if a condition is met bevchapman Excel Worksheet Functions 2 March 16th 09 03:45 PM
Clear Contents Of Cells Where Value = 0 carl Excel Worksheet Functions 3 July 6th 07 06:02 PM
Paste, clear and ignore contents and... automatically! Pepe \(Madrid\) Excel Programming 4 January 4th 07 02:58 PM
clear cells unless contents are in bold John Jones Excel Programming 1 August 24th 05 01:07 PM
Clear Contents - NonBold cells Steve Excel Discussion (Misc queries) 3 February 13th 05 11:36 PM


All times are GMT +1. The time now is 03:27 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"