Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default need programming help with nested event codes

Hi,

I have 2 event codes i need to put together. Specifically in column 7 I
need the ability to have multiple events AND to be able to use a dependent
cell (ie show full name but only input the number). I can't figure out how
to insert the dependent cell code so that when I put in a multiple event it
also runs the dependent cell code too. Right now it only does the dependent
cell code for the first value and not the for the succeeding values in my
validation drop down. Your help would be much appreciated.

Thanks (below is the code, I am using codes that I found posted on this
website, THANKS!)

Timber
~~~~~~~~~~~~~~~~~~
Option Explicit

Private Sub Worksheet_Change(ByVal Target As Range)
Dim rngDV As Range
Dim oldVal As String
Dim newVal As String
If Target.Count 1 Then GoTo exitHandler

On Error Resume Next
Set rngDV = Cells.SpecialCells(xlCellTypeAllValidation)
On Error GoTo exitHandler

If rngDV Is Nothing Then GoTo exitHandler

If Intersect(Target, rngDV) Is Nothing Then
'do nothing
Else
Application.EnableEvents = False
newVal = Target.Value
Application.Undo
oldVal = Target.Value
Target.Value = newVal
If Target.Column = 6 Or 7 Or 8 Or 9 Then
If oldVal = "" Then
'do nothing
Else
If newVal = "" Then
'do nothing
Else
Target.Value = oldVal _
& ", " & newVal
End If
End If
End If
End If

exitHandler:
Application.EnableEvents = True


End Sub

Private Sub Worksheet_Change1(ByVal Target As Range)
On Error GoTo errHandler
If Target.Cells.Count 1 Then GoTo exitHandler
If Target.Column = 7 Then
If Target.Value = "" Then GoTo exitHandler
Application.EnableEvents = False
Target.Value = Worksheets("Background").Range("C1") _
.Offset(Application.WorksheetFunction _
.Match(Target.Value, Worksheets("Background").Range("BCRCOMBO"), 0), 0)
End If

exitHandler:
Application.EnableEvents = True
Exit Sub

errHandler:
If Err.Number = 13 Or Err.Number = 1004 Then
GoTo exitHandler
Else
Resume Next
End If

End Sub

Sub MyFix()
Application.EnableEvents = True

End Sub




  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default need programming help with nested event codes

Not sure I understand what your problem is, but try this

Option Explicit

Private Sub Worksheet_Change(ByVal Target As Range)
Dim rngDV As Range
Dim oldVal As String
Dim newVal As String
If Target.Count 1 Then GoTo exitHandler

On Error Resume Next
Set rngDV = Cells.SpecialCells(xlCellTypeAllValidation)
On Error GoTo exitHandler

If rngDV Is Nothing Then GoTo exitHandler

If Intersect(Target, rngDV) Is Nothing Then
'do nothing
Else
Application.EnableEvents = False
newVal = Target.Value
Application.Undo
oldVal = Target.Value
Target.Value = newVal
If Target.Column = 6 Or 7 Or 8 Or 9 Then
If oldVal < "" Then
If newVal < "" Then
Target.Value = oldVal _
& ", " & newVal
End If
End If
End If
End If

If Target.Column = 7 Then
If Target.Value = "" Then GoTo exitHandler
Application.EnableEvents = False
Target.Value = Worksheets("Background").Range("C1") _
.Offset(Application.WorksheetFunction _
.Match(Target.Value, Worksheets("Background").Range("BCRCOMBO"), 0),
0)
End If

exitHandler:
Application.EnableEvents = True

End Sub




--
HTH

Bob Phillips

(remove nothere from email address if mailing direct)

"timber" wrote in message
...
Hi,

I have 2 event codes i need to put together. Specifically in column 7 I
need the ability to have multiple events AND to be able to use a dependent
cell (ie show full name but only input the number). I can't figure out

how
to insert the dependent cell code so that when I put in a multiple event

it
also runs the dependent cell code too. Right now it only does the

dependent
cell code for the first value and not the for the succeeding values in my
validation drop down. Your help would be much appreciated.

Thanks (below is the code, I am using codes that I found posted on this
website, THANKS!)

Timber
~~~~~~~~~~~~~~~~~~
Option Explicit

Private Sub Worksheet_Change(ByVal Target As Range)
Dim rngDV As Range
Dim oldVal As String
Dim newVal As String
If Target.Count 1 Then GoTo exitHandler

On Error Resume Next
Set rngDV = Cells.SpecialCells(xlCellTypeAllValidation)
On Error GoTo exitHandler

If rngDV Is Nothing Then GoTo exitHandler

If Intersect(Target, rngDV) Is Nothing Then
'do nothing
Else
Application.EnableEvents = False
newVal = Target.Value
Application.Undo
oldVal = Target.Value
Target.Value = newVal
If Target.Column = 6 Or 7 Or 8 Or 9 Then
If oldVal = "" Then
'do nothing
Else
If newVal = "" Then
'do nothing
Else
Target.Value = oldVal _
& ", " & newVal
End If
End If
End If
End If

exitHandler:
Application.EnableEvents = True


End Sub

Private Sub Worksheet_Change1(ByVal Target As Range)
On Error GoTo errHandler
If Target.Cells.Count 1 Then GoTo exitHandler
If Target.Column = 7 Then
If Target.Value = "" Then GoTo exitHandler
Application.EnableEvents = False
Target.Value = Worksheets("Background").Range("C1") _
.Offset(Application.WorksheetFunction _
.Match(Target.Value, Worksheets("Background").Range("BCRCOMBO"), 0),

0)
End If

exitHandler:
Application.EnableEvents = True
Exit Sub

errHandler:
If Err.Number = 13 Or Err.Number = 1004 Then
GoTo exitHandler
Else
Resume Next
End If

End Sub

Sub MyFix()
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
why does userform close after programming worksheet event with CreateEventProc or AddFromString tr00per Excel Programming 3 February 4th 06 10:09 PM
Linking worksheet event codes Mr. G. Excel Worksheet Functions 7 July 15th 05 06:15 PM
programming the VBE for a new event procedure mark kubicki Excel Programming 3 August 18th 04 04:43 PM
Event Procedure Programming Jeff Armstrong Excel Programming 1 July 29th 04 03:54 PM


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