PDA

View Full Version : [SOLVED:] Linking/merging two worksheet_change functions



PureBluff
01-07-2014, 06:49 PM
Hi all, Probably a very simple one for you guys -

How would I go about linking these two in the same worksheet_change PvtSub?

I've commented out the second one for obvious reasons.


Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Column = 1 Then
With Target.Offset(0, 1)
.NumberFormat = "dd:mmm:yy"
.Value = Date
With Target.Offset(0, 2)
.NumberFormat = "hh:mm"
.Value = Time
End With
End With
End If
End Sub


'If Target.Column = 13 Then
'With Target.Offset(0, 1)
'.NumberFormat = "dd:mmm:yy"
'.Value = Date
'With Target.Offset(0, 2)
'.NumberFormat = "hh:mm"
'.Value = Time
'End With
'End With
'End If
'End Sub

Thanks!

Aussiebear
01-07-2014, 08:39 PM
If the Offset targets are indeed different then I'd try


Private Sub Worksheet_Change(Target As Range)
If Target.Column = 1 Then
With Target.Offset(0, 1)
.NumberFormat = "dd:mmm:yy"
.Value = Date
With Target.Offset(0, 2)
.NumberFormat = "hh:mm"
.Value = Time
End With
End With
End If
Else
If Target.Column = 13 Then
With Target.Offset(0, 1)
.NumberFormat = "dd:mmm:yy"
.Value = Date
With Target.Offset(0, 2)
.NumberFormat = "hh:mm"
.Value = Time
'End With
End With
End If
End Sub

PureBluff
01-08-2014, 01:59 AM
Sadly that returns;

Procedure declaration does not match description of event or procedure having same name

westconn1
01-08-2014, 02:37 AM
try changing to
Private Sub Worksheet_Change(ByVal Target As Range)

as the code is the same for either column, you could use

If Target.Column = 1 Or Target.Column = 13 Then

PureBluff
01-08-2014, 02:47 AM
try changing to
Private Sub Worksheet_Change(ByVal Target As Range)

as the code is the same for either column, you could use

If Target.Column = 1 Or Target.Column = 13 Then

Legend :D Thank You!!!