H o l a:
Te anexo la macro para verificar que no existan duplicados.
'
Private Sub CommandButton1_Click()
'Por.Dante Amor
'
'GUARDAR
'
'If TextBox1 = "" Then cad = cad & "CODIGO. "
If TextBox1 = "" Then cad = cad & "TITULO. "
'If TextBox2 = "" Then cad = cad & "TOMO-VOLUMEN. "
If TextBox3 = "" Then cad = cad & "AUTOR. "
If TextBox4 = "" Then cad = cad & "EDITORIAL. "
If TextBox5 = "" Then cad = cad & "AÑO. "
If ComboBox1 = "" Then cad = cad & "IDIOMA. "
If ComboBox2 = "" Then cad = cad & "TIPO-DOCUMENTOS. "
If ComboBox3 = "" Then cad = cad & "CATEGORIA."
If cad <> "" Then
MsgBox "Faltan los siguientes datos: " & cad
For i = 1 To 5
If Controls("TextBox" & i) = "" And i <> 2 Then
Controls("TextBox" & i).SetFocus
Exit Sub
End If
Next
For i = 1 To 3
If Controls("ComboBox" & i) = "" Then
Controls("ComboBox" & i).SetFocus
Exit Sub
End If
Next
Exit Sub
End If
'
'Validar datos
'
titulo = TextBox1
existe = False
Set h1 = Sheets("TITULOS")
Set r = h1.Columns("B")
Set b = r.Find(titulo, lookat:=xlWhole, LookIn:=xlValues)
If Not b Is Nothing Then
ncell = b.Address
Do
If h1.Cells(b.Row, "C") = TextBox2 And _
h1.Cells(b.Row, "D") = TextBox3 And _
h1.Cells(b.Row, "E") = TextBox4 And _
h1.Cells(b.Row, "F") = TextBox5 And _
h1.Cells(b.Row, "G") = ComboBox1 And _
h1.Cells(b.Row, "H") = ComboBox2 And _
h1.Cells(b.Row, "I") = ComboBox3 Then
existe = True
codigo = h1.Cells(b.Row, "A")
Exit Do
End If
'
Set b = r.FindNext(b)
Loop While Not b Is Nothing And b.Address <> ncell
End If
'
'Guardar datos
If existe = False Then
u = h1.Range("A" & Rows.Count).End(xlUp).Row + 1
h1.Cells(u, "A") = Label1
For i = 1 To 5
h1.Cells(u, i + 1) = Controls("TextBox" & i)
Next
j = 7
For i = 1 To 3
h1.Cells(u, j) = Controls("Combobox" & i)
j = j + 1
Next
'
'Actualizar combos
Set h3 = Sheets("CATALOGOS")
For i = 1 To 3
Set b = h3.Columns(i).Find(Controls("Combobox" & i), lookat:=xlWhole)
If b Is Nothing Then
u = h3.Cells(Rows.Count, i).End(xlUp).Row + 1
h3.Cells(u, i) = Controls("Combobox" & i)
h3.Range(h3.Cells(1, i), h3.Cells(u, i)).Sort Key1:=h3.Cells(2, i), Order1:=xlAscending, _
Header:=xlGuess, OrderCustom:=1, MatchCase:=False, _
Orientation:=xlTopToBottom, DataOption1:=xlSortNormal
End If
Next
For i = 2 To h3.Range("A" & Rows.Count).End(xlUp).Row
ComboBox1.AddItem h3.Cells(i, "A")
Next
For i = 2 To h3.Range("B" & Rows.Count).End(xlUp).Row
ComboBox2.AddItem h3.Cells(i, "B")
Next
For i = 2 To h3.Range("C" & Rows.Count).End(xlUp).Row
ComboBox3.AddItem h3.Cells(i, "C")
Next
reg = Val(reg) + 1
Label1 = "R" & Format(reg, "000000")
'
MsgBox "Registro guardado"
Else
MsgBox "Registro ya existe, con el código " & codigo, vbCritical, "ERROR"
End If
'
'Limpiar datos
For i = 1 To 5
Controls("TextBox" & i) = ""
Next
For i = 1 To 3
Controls("Combobox" & i) = ""
Next
TextBox1.SetFocus
End Subs a l u d o s