Hi!
I have a problem with two codes in VBA.
Im trying to combine the codes that insert a date in a cell, if i entered a value in the cell behind and a second code, that locks the cells that contains any value. They are work separatly.
I tried the "Call" function, named the two codes, then insert them below in sequence, but nothing happened.
After that, i tried a "Target" function. The difference was, in this method i used two moduls where i inserted the codes. This time i get the "Sub or function not defined!" error messege. It works in excel 2007 but i work in 2013.
Can anyone help me with this?
These are my codes:
I have a problem with two codes in VBA.
Im trying to combine the codes that insert a date in a cell, if i entered a value in the cell behind and a second code, that locks the cells that contains any value. They are work separatly.
I tried the "Call" function, named the two codes, then insert them below in sequence, but nothing happened.
After that, i tried a "Target" function. The difference was, in this method i used two moduls where i inserted the codes. This time i get the "Sub or function not defined!" error messege. It works in excel 2007 but i work in 2013.
Can anyone help me with this?
These are my codes:
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
On Error GoTo ErrHnd:
If Target.Column = 2 Then
Application.EnableEvents = False
If Not IsDate(Range("C" & Target.Row).Value) Then
Range("C" & Target.Row).Value = Format(Date, "yyyy/mm/dd")
End If
Application.EnableEvents = True
End If
Exit Sub
ErrHnd:
Err.Clear
Application.EnableEvents = True
End Sub
And which locks the cells in range:
Dim xRg As Range
On Error Resume Next
Set xRg = Intersect(Range("A1:P1450"), Target)
If xRg Is Nothing Then Exit Sub
Target.Worksheet.Unprotect Password:="Epitomernok86"
xRg.Locked = True
Target.Worksheet.Protect Password:="Epitomernok86"
End Sub