Visual Basic - Visual añadir dos excel para comparar

Life is soft - evento anual de software empresarial
 
Vista:
sin imagen de perfil

Visual añadir dos excel para comparar

Publicado por patricio (3 intervenciones) el 22/02/2016 18:55:05
Estimados,

Soy nuevo por aca, estoy haciendo un validador de datos en Visual, donde tomo un archivo excel y valido las diferentes hojas y celdas que contiene eso lo pude hacer, pero ahora necesito añadir el mismo archivo y seleccionar un segundo archivo excel que deben donde se debe validar la informacion del archivo 1 con el 2.


Tengo una macro que realiza esa acción (adjunto código), pero no se como hacerlo en visual basic

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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
Sub validacion_bs_crs()
 
msg = MsgBox("Esta aplicación realiza las validaciones PRIMERO DEBE SELECCIONAR EL REM SERIE A Y LUEGO LA SERIE BS DEL ESTABLECIMIENTO Y MES A REVISAR" & Chr(13) & "                                                     ¿Desea comenzar la revisión?", vbYesNo + vbQuestion)
If msg = vbNo Then
GoTo Fin
End If
 
Dim path As Variant
    path = Application.GetOpenFilename("Archivo Excel REM Serie A del establecimento , *.xls*", _
    , "PASO 1/2: Seleccione el REM Serie A del establecimiento y mes.")
 
Dim path1 As Variant
path1 = Application.GetOpenFilename("Archivo Excel REM Serie BS del establecimiento , *.xls*", _
    , "PASO 2/2: Seleccione el REM Serie BS del establecimiento y mes.")
 
    If path1 = False Then
    MsgBox "No se seleccionó ningun archivo."
 
 Else
 
Workbooks.Open Filename:=path
Workbooks.Open Filename:=path1
 
 
strNombre = ActiveSheet.Parent.FullName
 
Sheets("NOMBRE").Select
 
strValor157 = Trim(Range("B02").Value)
strValor158 = Trim(Range("B03").Value)
strValor159 = Trim(Range("B04").Value)
strValor160 = Trim(Range("B05").Value)
strValor161 = Trim(Range("B06").Value)
strValor162 = Trim(Range("B07").Value)
 
 
If strValor157 = "" Then
MsgBox "Falta completar la COMUNA"
Range("B02").Select
'Exit Sub
End If
 
If strValor158 = "" Then
MsgBox "Falta completar el NOMBRE DEL ESTABLECIMIENTO"
Range("B03").Select
'Exit Sub
End If
 
If strValor159 = "" Then
MsgBox "Falta completar el TIPO DE ESTABLECIMIENTO"
Range("B04").Select
'Exit Sub
End If
 
If strValor160 = "" Then
MsgBox "Falta completar la DEPENDENCIA del establecimiento"
Range("B05").Select
'Exit Sub
End If
 
If strValor161 = "" Then
MsgBox "Falta completar el MES"
Range("B06").Select
'Exit Sub
End If
 
If strValor162 = "" Then
MsgBox "Falta completar el AÑO"
Range("B07").Select
'Exit Sub
End If
 
Sheets("BS0").Select
 
If Cells(333, 3) = 0 Then
MsgBox "REVISAR REM BS0: No viene dato en la SECCION N: 'FACTURACION COMPRA DE SERVICIOS'. Favor Revisar."
Range("C330").Select
'Exit Sub
End If
 
 
Sheets("BS17A").Select
 
'TOTAL V/S PROCEDENCIA
'Inicializar contador de coincidencias
cont = 0
 valor = "No cuadra total v/s procedencia"
 valor = " El nº de beneficiarios en IQ electivas mayores ambulatorias, NO puede ser MAYOR que el total de pacientes en IQ electivas mayores ambulatorias "
 
 
'Primera búsqueda del valor dentro del rango
Set resultado = Range("W12:W1987").Find(What:=valor, _
                    LookIn:=xlValues, _
                    LookAt:=xlPart, _
                    SearchOrder:=xlByColumns, _
                    SearchDirection:=xlNext, _
                    MatchCase:=True, _
                    SearchFormat:=True)
 
'Si el resultado de la búsqueda no es vacío
If Not resultado Is Nothing Then
    primerResultado = resultado.Address
 
    'Inicia bucle para hacer varias búsquedas
    Do
        cont = cont + 1
 
        'Cambia el color de fondo de la celda
        'resultado.Interior.ColorIndex = 6
 
        'Vuelve a buscar el valor
        Set resultado = Range("W12:W1987").FindNext(resultado)
 
    Loop While Not resultado Is Nothing And _
        resultado.Address <> primerResultado
        MsgBox "REVISAR REMBS17A: No cuadra PROCEDENCIA V/S TOTAL en una fila. o hay un error de Beneficiarios en IQ electivas mayores ambulatorias. Favor revisar Columna W."
End If
 
 
Range("W12").Select
 
' AGREGAR ESTE MENSAJE: El total intervenciones quirúrgicas no debe ser distinto a la suma según el % de facturación
 
'-------------------------COMIENZO VALIDACIONES:----------------
 
Sheets("BS17").Select
 
 
Set varsuma01 = Worksheets("BS17").Range("C96:C102")
respuesta01 = Application.WorksheetFunction.Sum(varsuma01)
If (Cells(85, 5) + Cells(85, 9)) <> respuesta01 Then
MsgBox "REVISAR REM BS17: No coinciden el TOTAL DE INTERVENCIONES QUIRÚRGICAS de la Sección E.1 (Celda E85 + I85) con la sección F.1 'INTERVENCIONES QUIRÚRGICAS POR TIPO DE INTERVENCIÓN'(Celdas C96 a C102). Favor Revisar."
Range("D29:K32").Select
'Exit Sub
End If
 
Set varsuma02 = Worksheets("BS17").Range("D96:D102")
respuesta02 = Application.WorksheetFunction.Sum(varsuma02)
If Cells(85, 5) <> respuesta02 Then
MsgBox "REVISAR REM BS17: No coinciden el TOTAL DE INTERVENCIONES QUIRÚRGICAS A BENEFICIARIOS de la Sección E.1 (Celda E85) con la sección F.1 'INTERVENCIONES QUIRÚRGICAS POR TIPO DE INTERVENCIÓN' A BENEFICIARIOS (Celdas D96 a D102). Favor Revisar."
Range("D96:D102").Select
'Exit Sub
End If
 
 
 
 
Set varsuma70 = Worksheets("BS17A").Range("J1990:M1990")
respuesta70 = Application.WorksheetFunction.Sum(varsuma70)
 
Set varsuma71 = Worksheets("BS17").Range("C98:F98")
respuesta71 = Application.WorksheetFunction.Sum(varsuma71)
 
If respuesta70 <> respuesta71 Then
MsgBox "REVISAR REM BS17: No coinciden las CIRUGÍAS ELECTIVAS MAYORES del REM BS17 fila 98 con el REM BS 17A fila suma 1990 columnas J a M. Favor Revisar."
Range("D96:D102").Select
End If
 
Sheets("BS17A").Select
 
'fila 16 total OK
Set varsuma11 = Workbooks("112300A.xls").Worksheets("A07").Range("B12:B31")
respuesta11 = Application.WorksheetFunction.Sum(varsuma11)
Set varsuma12 = Workbooks("112300A.xls").Worksheets("A07").Range("B33:B57")
respuesta12 = Application.WorksheetFunction.Sum(varsuma12)
 
 
'BS17A fila 1887 vs rem SA09 fila 61 TOTALok
Set varsuma50 = Workbooks("112300A.xls").Worksheets("A09").Range("D36")
respuesta50 = Application.WorksheetFunction.Sum(varsuma50)
 
If (Workbooks("112300BS.xls").Sheets("BS17A").Cells(1887, 3).Value) <> respuesta50 Then
MsgBox "REVISAR REM BS17A, Fila 1887 NO coincide con lo informado en el REM SA 09 Fila D36. Favor Revisar. El valor registado en el REM A09 es: " & respuesta50
End If




Como se puede hacer eso, ideas comentarios. para buscar como lo podría seguir se agradeciera mucho,


Saludos

Patricio M
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: 4
Ha aumentado su posición en 25 puestos en Visual Basic (en relación al último mes)
Gráfica de Visual Basic

Visual añadir dos excel para comparar

Publicado por Paolo (76 intervenciones) el 25/02/2016 02:29:53
hola amigo...

lo que quieres comparar es la fila completa o celda por celda??
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