Hello all!
First post! I've been lurking around here for a while and I think you people are all incredible. I've learned a lot so far.
So here is my question. I have two event changes for a single sheet. The first event change allows me to enter multiple items in the same cell from picking from a drop down list. Here it is:
Private Sub Worksheet_Change(ByVal Target As Range)
Dim rngDV As Range
Dim oldVal As String
Dim newVal As String
'run code if only one cell was changed
If Target.Count > 1 Then GoTo exitHandler
Select Case Target.Column
Case 2, 3 'this Case line works for column B only
'Case 2, 5, 6 'this Case line works for multiple columns
On Error Resume Next
'check the cell for data validation
Set rngDV = Target.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 oldVal <> "" Then
If newVal <> "" Then
Target.Value = oldVal _
& ", " & newVal
End If
End If
End If
End Select
exitHandler:
Application.EnableEvents = True
End Sub
'=====End Copy here
The second piece makes a DTPicker invisible when the cell that contains it is not selected. Here it is:
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Address = "$F$7" Then
Me.DTPicker1.Visible = True
Else
Me.DTPicker1.Visible = False
End If
If Target.Address = "$F$8" Then
Me.DTPicker2.Visible = True
Else
Me.DTPicker2.Visible = False
End If
If Target.Address = "$F$9" Then
Me.DTPicker3.Visible = True
Else
Me.DTPicker3.Visible = False
End If
If Target.Address = "$F$10" Then
Me.DTPicker4.Visible = True
Else
Me.DTPicker4.Visible = False
End If
If Target.Address = "$F$11" Then
Me.DTPicker5.Visible = True
Else
Me.DTPicker5.Visible = False
End If
If Target.Address = "$G$7" Then
Me.DTPicker6.Visible = True
Else
Me.DTPicker6.Visible = False
End If
If Target.Address = "$G$8" Then
Me.DTPicker7.Visible = True
Else
Me.DTPicker7.Visible = False
End If
If Target.Address = "$G$9" Then
Me.DTPicker8.Visible = True
Else
Me.DTPicker8.Visible = False
End If
If Target.Address = "$G$10" Then
Me.DTPicker9.Visible = True
Else
Me.DTPicker9.Visible = False
End If
If Target.Address = "$G$11" Then
Me.DTPicker10.Visible = True
Else
Me.DTPicker10.Visible = False
End If
If Target.Address = "$C$2" Then
Me.DTPicker11.Visible = True
Else
Me.DTPicker11.Visible = False
End If
If Target.Address = "$C$3" Then
Me.DTPicker12.Visible = True
Else
Me.DTPicker12.Visible = False
End If
If Target.Address = "$I$2" Then
Me.DTPicker13.Visible = True
Else
Me.DTPicker13.Visible = False
End If
If Target.Address = "$I$3" Then
Me.DTPicker14.Visible = True
Else
Me.DTPicker14.Visible = False
End If
End Sub
Now I know my code is not sophisticated and repetitive so please forgive me.
Someone gave the idea of doing the following:
Option Explicit
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Call ChangeEvent1(Target)
Call ChangeEvent2(Target)
End Sub
Private Sub ChangeEvent1(ByVal Target As Range)
'
'Change Event 1 Code
'
End Sub
Private Sub ChangeEvent2(ByVal Target As Range)
'
'Change Event 2 Code
'
End Sub
But still only the DTPicker code works. Anyone have any ideas? I won't be able to check your responses for a little while but will be back as soon as I can!
Thanks!
Bookmarks