Macro para grabar información en una base de datos
La macro que adjunto la uso para grabar información en la hoja llamada "BASE DATOS PROVEEDORES" pero no me busca la fila vacía sino que se queda "estancada" en una especifica, la cual ya tiene información y por ende la reemplaza, me guarda la nueva pero la anterior me la borra, que podría estar pasando o que error tiene la macro
Espero me puedan ayudar
Private Sub CommandButton1_Click()
Application.ScreenUpdating = False
Sheets("BASE DATOS PROVEEDORES").Visible = True
Sheets("BASE DATOS PROVEEDORES").Select
Dim fila As Long
Dim duplicados As Boolean
'Obtener la fila disponible
fila = Application.WorksheetFunction.CountA(Range("A:A")) + 1
duplicados = False
'Validar si se han ingresado datos duplicados
For i = 1 To fila
If Cells(i, 1).Value = UserForm1.TextBox1.Value Then
If Cells(i, 2).Value = UserForm1.TextBox2.Value Then
If Cells(i, 3).Value = UserForm1.TextBox3.Value Then
'Se encontraron datos duplicados
MsgBox "Datos duplicados en la fila " & i
duplicados = True
End If
End If
End If
Next i
If Not duplicados Then
'Insertar datos capturados
Cells(fila, 1).Value = UserForm1.TextBox1.Value
Cells(fila, 2).Value = UserForm1.TextBox2.Value
Cells(fila, 3).Value = UserForm1.TextBox3.Value
'Limpiar cajas de texto
UserForm1.TextBox1.Value = ""
UserForm1.TextBox2.Value = ""
UserForm1.TextBox3.Value = ""
'Notificar al usuario
MsgBox "Datos insertados en la fila " & fila
End If
End Sub