Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10
Default what takes precedence between change and selectionchange?

Hi

i have a single sheet with these 2 events:

Private Sub Worksheet_SelectionChange(ByVal Target As Range)

Private Sub Worksheet_Change(ByVal Target As Range)

Is there a particular order of execution between these two in excel?


Also how can I disable the selectionchange from executing if the user
deletes a value? When the value is deleted it puts it back

Thank you
Susan Hayes

Private Sub Worksheet_Change(ByVal Target As Range)

Dim mytime
mytime = Now
On Error GoTo ErrHandler
If Target.Column <= 26 Then
Application.EnableEvents = False
If mytime Range("O" & Target.Row).Value + 0.5 And Range("P"
& Target.Row).Value = 0 And _
Range("H" & Target.Row).Value = Range("S" & Target.Row).Value
Then
Range("C" & Target.Row).Value = "Historical"


End If

End If

ErrHandler:
Application.EnableEvents = True
End Sub
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,298
Default what takes precedence between change and selectionchange?

well you can't do both at the same time, so whatever is done first, that
event gets fired.

The only way to repopulate a cell with any value or formula is to have that
value/formula saved somewhere so that if the target cell value is "" you can
recover the data.
One way would be to have a hidden sheet. each time a valid entry id made,
the value is also copied to the same cell in the hidden sheet. if a cells
value is deleted, then the 'saved' value is recovered. of course the copy
sheet doesn't have to be hidden.

In this example sheet1 is ny data entry sheet and sheet3 is the copy.put the
code in sheet1's code page

Option Explicit
Private Sub Worksheet_Change(ByVal Target As Range)
If Trim(Target.Value) = "" Then
Target = Worksheets("sheet3").Range(Target.Address)
Else
Worksheets("sheet3").Range(Target.Address) = Target
End If
End Sub

enter a value into any cell on sheet1. look at sheet3 - see that value. back
in sheet1, change the value & check sheet3. in sheet1 delete the value...the
last good value appears. enter a space and the last good value appears



"susan" wrote:

Hi

i have a single sheet with these 2 events:

Private Sub Worksheet_SelectionChange(ByVal Target As Range)

Private Sub Worksheet_Change(ByVal Target As Range)

Is there a particular order of execution between these two in excel?


Also how can I disable the selectionchange from executing if the user
deletes a value? When the value is deleted it puts it back

Thank you
Susan Hayes

Private Sub Worksheet_Change(ByVal Target As Range)

Dim mytime
mytime = Now
On Error GoTo ErrHandler
If Target.Column <= 26 Then
Application.EnableEvents = False
If mytime Range("O" & Target.Row).Value + 0.5 And Range("P"
& Target.Row).Value = 0 And _
Range("H" & Target.Row).Value = Range("S" & Target.Row).Value
Then
Range("C" & Target.Row).Value = "Historical"


End If

End If

ErrHandler:
Application.EnableEvents = True
End Sub

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 SET UP A PRECEDENCE DIAGRAM? G Heard Excel Worksheet Functions 1 May 30th 07 05:49 AM
Takes too long for Filedialog to change directory File selection in office2003 Excel Discussion (Misc queries) 1 May 1st 06 05:33 AM
VBA Precedence Problem Mike King Excel Programming 11 June 16th 05 10:13 PM
Remember SelectionChange range in the Change sheet event? Marie J-son[_5_] Excel Programming 2 January 30th 05 09:40 AM
optionbutton takes two clicks to change value Will Gardner Excel Programming 2 December 1st 04 03:00 PM


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