Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 13
Default worksheet change event only if cell was blank

How can you limit change event to run only if changed cell was blank.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 703
Default worksheet change event only if cell was blank

On 22 Jun., 12:21, Sliman wrote:
How can you limit change event to run only if changed cell was blank.


Hi

Look at this:

Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Address = "$A$1" Then
If Target.Value = "" Then
'Do your stuff
End If
End If
End Sub

Regards,
Per
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,501
Default worksheet change event only if cell was blank

Hi,

This can also work on a range of cells and if your unsure of how to change
it to do that then post back.

Private Sub Worksheet_Change(ByVal Target As Range)
If IsEmpty(Target) Then
If Target.Address = "$A$1" Then
MsgBox "Do something"
End If
End If
End Sub

Mike

"Sliman" wrote:

How can you limit change event to run only if changed cell was blank.

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,058
Default worksheet change event only if cell was blank

Adapt something like:

Private Sub Worksheet_Change(ByVal Target As Range)
Set a1 = Range("A1")
Set t = Target
If Intersect(a1, t) Is Nothing Then
If a1.Value = "" Then
wasblank = True
Else
wasblank = False
End If
Exit Sub
Else
If wasblank And a1.Value < "" Then
MsgBox ("changed from blank to nonblank")
wasblank = False
End If
If a1.Value = "" Then
wasblank = True
End If
End If
End Sub

This remembers what WAS in A1.
--
Gary''s Student - gsnu2007j


"Sliman" wrote:

How can you limit change event to run only if changed cell was blank.

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,071
Default worksheet change event only if cell was blank

This should do what you want. HTH Otto
Private Sub Worksheet_Change(ByVal Target As Range)
Dim OldValue As Variant
Dim NewValue As Variant
If Target.Count 1 Then Exit Sub
NewValue = Target.Value
Application.EnableEvents = False
Application.Undo
OldValue = Target.Value
Target.Value = NewValue
Application.EnableEvents = True
If OldValue = "" Then
'Do your thing here
End If
End Sub
"Sliman" wrote in message
...
How can you limit change event to run only if changed cell was blank.



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
Calculation of cell value with worksheet change event Raj[_2_] Excel Programming 2 May 30th 08 05:20 PM
change event on specific cell rather than worksheet frendabrenda1 Excel Discussion (Misc queries) 10 September 21st 06 03:37 AM
Cell value change to trigger macro (worksheet change event?) Neil Goldwasser Excel Programming 4 January 10th 06 01:55 PM
Change Cell from Validated List Not Firing Worksheet Change Event [email protected] Excel Programming 3 October 4th 04 03:00 AM


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