PC Review


Reply
Thread Tools Rate Thread

Clear Contents of Offset cells automatically

 
 
K
Guest
Posts: n/a
 
      19th Aug 2009
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
 
Reply With Quote
 
 
 
 
Mike H
Guest
Posts: n/a
 
      19th Aug 2009
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
>

 
Reply With Quote
 
Per Jessen
Guest
Posts: n/a
 
      19th Aug 2009
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" <(E-Mail Removed)> skrev i meddelelsen
news:f400d76e-cd50-4eb3-88a3-(E-Mail Removed)...
> 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


 
Reply With Quote
 
K
Guest
Posts: n/a
 
      19th Aug 2009
thanks lot guys

 
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
Populate one cell with an offset cells contents Fleone Microsoft Excel Programming 2 19th Dec 2007 09:47 PM
Clear Contents Of Cells Where Value = 0 =?Utf-8?B?Y2FybA==?= Microsoft Excel Worksheet Functions 3 6th Jul 2007 06:02 PM
Paste, clear and ignore contents and... automatically! Pepe \(Madrid\) Microsoft Excel Programming 4 4th Jan 2007 02:58 PM
Automatically clear contents of a field louonline Microsoft Access Forms 5 28th Apr 2006 04:05 AM
clear contents cells of unprotected cells =?Utf-8?B?RWQ=?= Microsoft Excel Programming 6 12th Jan 2006 06:09 PM


Features
 

Advertising
 

Newsgroups
 


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