Hacer funcionar el código de El dato ya existe
Hola tengo un botón GUARDAR que me da error cuando quiero guardar un dato nuevo.
específicamente en esta parte del código
If rango <> Empty Then
MsgBox "El dato ya existe", vbOKOnly + vbInformation, "AVISO"
TextBox1.SetFocus
Exit Sub
End If
, me gustaría que no me permita cargar uno nuevo si el Código ya existe.
los datos están asi.
CÓDIGO NOMBRE APELLIDO
En el código debe guardar del TextBox1
aca les dejo el código completo del botón.
Dim rango As Range
Private Sub GUARDAR_Click()
Sheets("Hoja1").Select
Dim strfila$, ctr As Control
If TextBox1 = "" Or TextBox2 = "" Or TextBox3 = "" Then
MsgBox "No dejes los datos personales en blanco", vbOKOnly + vbInformation, "AVISO"
TextBox1.SetFocus
Exit Sub
End If
If rango <> Empty Then
MsgBox "El dato ya existe", vbOKOnly + vbInformation, "AVISO"
TextBox1.SetFocus
Exit Sub
End If
Set rango = Range("A:A").Find(What:=TextBox1, _
LookAt:=xlWhole, LookIn:=xlValues)
strfila$ = [A65536].End(xlUp).Offset(1, 0).Row
Range("A" & strfila$) = TextBox1
Range("B" & strfila$) = TextBox2
Range("C" & strfila$) = TextBox3
For Each ctr In Me.Controls
If TypeOf ctr Is MSForms.TextBox Then
ctr = ""
End If
Next ctr
Range("A" & strfila$ & ":C" & strfila$).HorizontalAlignment = xlCenter
TextBox1.SetFocus
End Sub
