When I enter a form a record is added to the indicated row but after that I add another record and replace it and I do not understand why I think the code is right.
Function Insercion(Nombre_Completo As String, Domicilio As String, Telefono As String, Seccion As String) As String
Dim ultimaFila, filaRegistro, existe As Long
Dim confirmacionRegistro As String
confirmacionRegistro = "No"
ultimaFila = Range("D" & Rows.Count).End(xlUp).Row
If ultimaFila < 4 Then
filaRegistro = 4
Else
filaRegistro = ultimaFila + 1
End If
If ultimaFila < 4 Then
ultimaFila = 4
End If
existe = ExitenciaRegistro(Nombre_Completo, "D4:D" & ultimaFila)
If existe > 0 Then
MsgBox "Este Registro ya existe"
Insercion = confirmacionRegistro
Exit Function
End If
Base_De_Datos.Cells(filaRegistro, 4) = Nombre_Completo
Base_De_Datos.Cells(filaRegistro, 5) = Domicilio
Base_De_Datos.Cells(filaRegistro, 6) = Telefono
Base_De_Datos.Cells(filaRegistro, 7) = Seccion
MsgBox "Registrado"
confirmacionRegistro = " Ingresado"
Insercion = confirmacionRegistro
End Function
Private Function ExitenciaRegistro(Nombre_Completo As String, rangoConsulta As String) As Long
Dim numeroFila As Long
numeroFila = 0
With Base_De_Datos.Range(rangoConsulta)
Set c = .Find(Nombre_Completo, LookIn:=xlValues)
If Not c Is Nothing Then
numeroFila = c.Row
End If
End With
ExitenciaRegistro = numeroFila
End Function