0
Hi, I’m trying to improve the control spreadsheet of the company I work for, but I’m having trouble.
We have to register a customer’s call, I have already been able to fill in the Date and Time sheet automatically after filling in the Name field. What I want now is to protect the Date and Time fields at this time, so it cannot be changed. What is happening is that in some rows excel has blocked the entire line. Can anyone help me?
That’s the code I made so far.
Private Sub Worksheet_Change(ByVal Alvo As Range)
Dim limite_maximo As Integer
limite_maximo = 4000 ' limite ultima linha
If Alvo.Cells.Count > 1 Or IsEmpty(Alvo) Then Exit Sub
' faz nada se mais de uma célula modificada ou se deu delete
If Alvo.Column = 5 And Alvo.Row >= 4 And Alvo.Row <= limite_maximo Then
' o if acima seta onde vai iniciar e o range e = 5 (coluna), row (linha = 4)
' desliga captura do evento change
Application.EnableEvents = False
' muda a célula E da linha correspondente
' Desprotege
ActiveSheet.Unprotect
Alvo.Offset(0, -1).Value = Time() ' Registra a hora (A = 0, D = 3)
Alvo.Offset(0, -2).Value = Date ' Registra a data (A = 0, E = 4)
Linha = Alvo.Row
Range("C" & Linha).Locked = True
Range("e" & Linha).Locked = True
' Protege
ActiveSheet.Protect
' religa a captura de eventos
Application.EnableEvents = True
End If
End Sub
This is the spreadsheet
Daniel, thanks for your help. I did as I said, but there was a problem. He ended up locking other lines too, as in the image he locked from E7 to H7... I do not understand why he hangs other cells that I did not indicate. I have only indicated these columns Range("C" & line & ":E" & line).Cells.Locked = True You know why this happens?
– Rivolier
Strange. In a test I did not lock the other
– danieltakeshi
It did not lock all, only caught some that were not in the selection of vba. Can send me the file you made for me to see if there are any errors in my?
– Rivolier