Visual Basic para Aplicaciones - Duplicidad de datos en vba

Life is soft - evento anual de software empresarial
 
Vista:

Duplicidad de datos en vba

Publicado por Jesus Pool (6 intervenciones) el 13/08/2017 01:48:18
Hola buenas tardes, me pueden ayudar con la sig. linea de codigo lo que estoy buscando hacer es que quiero evitar que halla valores duplicados en mis registros para ser mas especificos no quiero que se permita guardar un codigo que ya este previamente añadido, la linea de codigo en mi boton guardar es esta ........pd. Gracias
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
Private Sub B_Guardar_Click()
For I = 1 To 1500
If Sheets("Productos").Cells(I + 6, 2).Text = "" Then
Sheets("Productos").Cells(I + 6, 2) = Text_Codigo.Text
Sheets("Productos").Cells(I + 6, 3) = C_Estatus.Text
Sheets("Productos").Cells(I + 6, 4) = Text_Denominaciondistintiva.Text
Sheets("Productos").Cells(I + 6, 5) = C_Laboratorio.Text
Sheets("Productos").Cells(I + 6, 6) = Text_RegistroSanitario.Text
Sheets("Productos").Cells(I + 6, 8) = C_Forma.Text
Sheets("Productos").Cells(I + 6, 9) = C_Administracion.Text
Sheets("Productos").Cells(I + 6, 10) = Text_Presentacion.Text
Sheets("Productos").Cells(I + 6, 11) = Text_Precio.Text
Sheets("Productos").Cells(I + 6, 13) = Text_cualitativa.Text
Sheets("Productos").Cells(I + 6, 14) = Text_Cuantitativa.Text
Sheets("Productos").Cells(I + 6, 15) = Text_Excipiente.Text
Sheets("Productos").Cells(I + 6, 17) = C_Temperatura.Text
Sheets("Productos").Cells(I + 6, 18) = C_Humedad.Text
Sheets("Productos").Cells(I + 6, 19) = C_Luz.Text
Sheets("Productos").Cells(I + 6, 21) = C_Clasificacion.Text
Sheets("Productos").Cells(I + 6, 23) = C_Controles.Text
Sheets("Productos").Cells(I + 6, 25) = C_Grupo.Text
Sheets("Productos").Cells(I + 6, 26) = C_Subgrupo.Text
Text_Codigo = Empty
C_Estatus = Empty
Text_Denominaciondistintiva = Empty
C_Laboratorio = Empty
Text_RegistroSanitario = Empty
C_Forma = Empty
C_Administracion = Empty
Text_Presentacion = Empty
Text_Precio = Empty
Text_cualitativa = Empty
Text_Cuantitativa = Empty
Text_Excipiente = Empty
C_Temperatura = Empty
C_Humedad = Empty
C_Luz = Empty
C_Clasificacion = Empty
C_Controles = Empty
C_Grupo = Empty
C_Subgrupo = Empty
Text_Codigo.SetFocus
Exit For
End If
Next
End Sub
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder
sin imagen de perfil
Val: 85
Ha aumentado 1 puesto en Visual Basic para Aplicaciones (en relación al último mes)
Gráfica de Visual Basic para Aplicaciones

Duplicidad de datos en vba

Publicado por David Garcia (4 intervenciones) el 13/08/2017 22:27:07
Puedes crear un procedimiento Sub para validar si el codigo se encuentra en la base de datos.

Ejemplo

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
Sub Validar()
Dim Lin As Long
Dim Sx As Boolean
With Hoja1
Lin = 3
    Do While .Cells(Lin, 1) <> ""
 
        If .Cells(Lin, 2) = Text_Codigo.Text Then
 
            Sx = True
        Else
            Sx = False
 
        End If
 
    Lin = Lin + 1
    Loop
End With
 
End Sub

Si el valor de la variable Booleana cambia a False, entonces que te permita registrar.
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar

Duplicidad de datos en vba

Publicado por Jesus Villalobos (6 intervenciones) el 16/08/2017 01:54:24
Men Gracias por el aporte, me funciono muy bien
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar