Visual Basic - Excell microsoft visual basic error 13 en tiempo de ejecucion

Life is soft - evento anual de software empresarial
 
Vista:
sin imagen de perfil
Val: 1
Ha aumentado su posición en 66 puestos en Visual Basic (en relación al último mes)
Gráfica de Visual Basic

Excell microsoft visual basic error 13 en tiempo de ejecucion

Publicado por Ramnses (1 intervención) el 09/11/2018 13:49:05
Saludos, tengo este error en excel cuando automatizo algo: error 13 en tiempo de ejecución, no coinciden los tipos.

He puesto en negrita y de otro tamano la area del codigo que me marca error






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
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
Sub CreateFixedWidthFile(strFile As String, ws As Worksheet, s() As Integer, a() As String, t() As String)
    Dim i As Long, j As Long
    Dim strLine As String, strCell As String
 
     'get a freefile
    Dim fNum As Long
    fNum = FreeFile
 
     'open the textfile
    Open strFile For Output As fNum
 
    'new line
    strLine = ""
 
    'Codigo Reclamante
    strCell = Left$(ws.Cells(4, 2).Value, 7)
    strLine = strLine & strCell & String$(7 - Len(strCell), Chr$(32))
 
    'Tipo Reclamante
    strCell = Left$(ws.Cells(4, 7).Value, 9)
    strLine = strLine & strCell & String$(9 - Len(strCell), Chr$(32))
 
    'Cantidad Lineas
    strCell = Left$(ws.Cells(2, 10).Value, 7)
    strLine = strLine & strCell & String$(7 - Len(strCell), Chr$(32))
 
    'Total a Pagar
    strCell = Left$(ws.Cells(3, 10).Value, 15)
    strLine = strLine & strCell & String$(15 - Len(strCell), Chr$(32))
 
    'Fecha del dia
    strLine = strLine & Format(Now(), "ddmmyy")
 
    'RNC
    strCell = Left$(ws.Cells(2, 3).Value, 9)
    strLine = strLine & strCell & String$(9 - Len(strCell), Chr$(32))
 
    Print #fNum, strLine
 
    For i = 8 To ws.Range("a65536").End(xlUp).Row
        strLine = ""
        'loop through each field
        For j = 0 To UBound(s)
            'Si es tipo fecha se convierte segun la mascara del layout
            If IsDate(ws.Cells(i, j + 1)) Then
              strCell = Format(ws.Cells(i, j + 1).Value, "ddmmyy")
          ElseIf t(j) = N Then
              

strCell = Replace(FormatNumber(ws.Cells(i, j + 1).Value, 2), ",", "")

 
            Else
              'Se eliminan guiones para Referencia (columna 1), Afiliado (Columna 3) y Cedula (columna 5) se eliminan los guiones
              If j = 0 Or j = 2 Or j = 4 Then
                strCell = Replace(ws.Cells(i, j + 1).Value, "-", "")
              ElseIf j = 17 Then
                strCell = Replace(Replace(Replace(ws.Cells(i, j + 1).Value, "F", "FT"), "C", "NC"), "D", "ND")
              Else
                strCell = ws.Cells(i, j + 1).Value
              End If
            End If
 
             'make sure we only take chars up to length of field (may want to output some sort of error if it is longer than field)
            If a(j) = L Then
              strCell = Left$(strCell, s(j))
            ElseIf a(j) = R Then
              strCell = Right$(strCell, s(j))
            End If
 
             'add on string of spaces with length equal to the difference in length between field length and value length
            strLine = strLine & strCell & String$(s(j) - Len(strCell), Chr$(32))
        Next j
         'write the line to the file
        Print #fNum, strLine
    Next i
     'close the file
    Close #fNum
End Sub
 
' Ejecuta las validaciones del archivo
Private Sub ValidaArchivo()
  On Error GoTo ErrorHandler
  '
  Dim i As Integer
  Dim e As Integer
  Dim v_error As String
  Dim dFechaDGII As Date
  Dim dFechaComp As Date
 
  '
  With Worksheets("DATA")
    '
    ' Valida que el reclamante se haya especifcado
    Worksheets("data").Cells(4, 29) = 0
    If Len(.Cells(4, 2)) = 0 Then
      .Cells(4, 2).Select
      result = MsgBox("El Código del Reclamante (Columna B4) debe ser especificado para ejecutar la validación.", vbOKOnly + vbCritical, "Error")
      Worksheets("data").Cells(4, 29) = -1
    ElseIf Len(.Cells(4, 4)) = 0 Then
      .Cells(4, 4).Select
      result = MsgBox("El Nombre del Reclamante (Columna D4) debe ser especificado para ejecutar la validación.", vbOKOnly + vbCritical, "Error")
      Worksheets("data").Cells(4, 29) = -1
    Else
      e = 0
      .Unprotect Password:="humsal"
 
    dFechaDGII = .Cells(1, 3)
 
      ' Error Desc Reset
      .Range("AA8:AA32000").ClearContents
      '
      ' Poner las letras en negro antes de comenzar
      With .Range("A8:AA32000").Font
          .ColorIndex = xlAutomatic
          .TintAndShade = 0
      End With
      '
      'For i = 8 To .Cells(2, 10) + 8 - 1
      For i = 8 To 32000
         '
         If i > 8 And Application.CountA(.Range(Cells(i, 1).Address & ":" & Cells(i, 25).Address)) = 0 Then
           Exit For
         End If
 
         v_error = ""
 
         ' Referencia Primera
         .Cells(i, 1) = UCase(.Cells(i, 1))
 
         If Len(.Cells(i, 1)) = 0 Then
           v_error = "La Referencia ARS (Columna #1) es obligatoria."
           e = e + 1
 
         ElseIf IsNumeric(Replace(Replace(.Cells(i, 1), "-", ""), "P", "")) = False Or InStr(.Cells(i, 1), ".") <> 0 Or Right(.Cells(i, 1), 1) = "-" Or Left(.Cells(i, 1), 1) = "-" Or Len(.Cells(i, 1)) - Len(Replace(.Cells(i, 1), "-", "")) > 3 Or Len(.Cells(i, 1)) - Len(Replace(.Cells(i, 1), "P", "")) > 1 Then
           If Len(v_error) > 0 Then
             v_error = v_error + Chr(10)
           End If
 
           v_error = v_error + "La Referencia ARS (Columna #1) debe contener solamente Números, Guiones (Máximo 3) y el Identificador P."
           e = e + 1
         End If
 
         ' Fecha de Servicio
         If Len(.Cells(i, 2)) = 0 Then
           If Len(v_error) > 0 Then
             v_error = v_error + Chr(10)
           End If
 
           v_error = v_error + "La Fecha de Servicio (Columna #2) es obligatoria."
           e = e + 1
 
         ElseIf IsDate(.Cells(i, 2)) = False Then
           If Len(v_error) > 0 Then
             v_error = v_error + Chr(10)
           End If
 
           v_error = v_error + "La Fecha de Servicio (Columna #2) no tiene un formato valido."
           e = e + 1
         End If
 
         ' Afiliado
         If Len(.Cells(i, 3)) = 0 Then
           If Len(v_error) > 0 Then
             v_error = v_error + Chr(10)
           End If
 
           v_error = v_error + "El Afiliado (Columna #3) es obligatorio."
           e = e + 1
 
         ElseIf IsNumeric(Replace(.Cells(i, 3), "-", "")) = False Then
           If Len(v_error) > 0 Then
             v_error = v_error + Chr(10)
           End If
 
           v_error = v_error + "El Afiliado (Columna #3) debe contener solamente números y guiones."
           e = e + 1
         End If
         '
         ' Total Reclamado
         If Len(.Cells(i, 6)) = 0 Then
           If Len(v_error) > 0 Then
             v_error = v_error + Chr(10)
           End If
 
           v_error = v_error + "El Total Reclamado (Columna #6) es obligatorio."
           e = e + 1
 
         ElseIf IsNumeric(.Cells(i, 6)) = False Then
           If Len(v_error) > 0 Then
             v_error = v_error + Chr(10)
           End If
 
           v_error = v_error + "El Total Reclamado (Columna #6) debe ser numérico."
           e = e + 1
         End If
 
         'Sumar la columna 7 y 8
         .Cells(i, 9) = .Cells(i, 7) + .Cells(i, 8)
 
         ' Total a Pagar
         If Len(.Cells(i, 9)) = 0 Then
           If Len(v_error) > 0 Then
             v_error = v_error + Chr(10)
           End If
 
           v_error = v_error + "El Total a Pagar (Columna #9) no debe ser cero, coloque un valor en la casilla Monto Servicio y/o Bien según corresponda."
           e = e + 1
 
         ElseIf IsNumeric(.Cells(i, 9)) = False Then
           If Len(v_error) > 0 Then
             v_error = v_error + Chr(10)
           End If
 
           v_error = v_error + "El Total a Pagar (Columna #9) debe ser numérico."
           e = e + 1
 
         ElseIf .Cells(i, 9) = 0 Then
           If Len(v_error) > 0 Then
             v_error = v_error + Chr(10)
           End If
 
           v_error = v_error + "El Total a Pagar (Columna #9) no debe ser cero, coloque un valor en la casilla Monto Servicio y/o Bien según corresponda."
           e = e + 1
 
         ElseIf .Cells(i, 9) <> (.Cells(i, 7) + .Cells(i, 8)) Then
           If Len(v_error) > 0 Then
             v_error = v_error + Chr(10)
           End If
 
           v_error = v_error + "El Total a Pagar (Columna #9) es la suma de Monto Servicios + Monto Bien, verifique."
           e = e + 1
         End If
 
        ' Fecha Factura
        If Len(.Cells(i, 12)) > 0 And IsDate(.Cells(i, 12)) = False Then
           If Len(v_error) > 0 Then
             v_error = v_error + Chr(12)
           End If
 
           v_error = v_error + "La Fecha de Factura (Columna 12) no tiene un formato valido."
           e = e + 1
         End If
 
         '.Cells(i, 27) = v_error
         '.Cells(4, 10) = e
 
       ' Tipo de Servicio
        .Cells(i, 13) = UCase(.Cells(i, 13))
 
        If Len(.Cells(i, 13)) = 0 Then
           If Len(v_error) > 0 Then
             v_error = v_error + Chr(10)
           End If
 
           v_error = v_error + "El Tipo de Servicio (Columna #13) es obligatorio."
           e = e + 1
 
         ElseIf .Cells(i, 13) <> "AMB" And .Cells(i, 13) <> "EME" And .Cells(i, 13) <> "HOS" And .Cells(i, 13) <> "LAB" And .Cells(i, 13) <> "FAR" And .Cells(i, 13) <> "ODO" Then
           If Len(v_error) > 0 Then
             v_error = v_error + Chr(10)
           End If
 
           v_error = v_error + "El Tipo de Servicio (Columna #13) no está dentro de las opciones válidas."
           e = e + 1
         End If
 
        ' Sub-Tipo de Servicio
         .Cells(i, 14) = UCase(.Cells(i, 14))
 
         If .Cells(i, 13) = "EME" Or .Cells(i, 13) = "HOS" Or .Cells(i, 13) = "LAB" Then
           .Cells(i, 14) = "OT"
         End If
 
         If Len(.Cells(i, 14)) = 0 Then
           If Len(v_error) > 0 Then
             v_error = v_error + Chr(10)
           End If
 
           v_error = v_error + "El Sub-Tipo de Servicio (Columna 14) es obligatorio."
           e = e + 1
 
         ElseIf .Cells(i, 14) <> "AQ" And .Cells(i, 14) <> "CS" And .Cells(i, 14) <> "CV" And .Cells(i, 14) <> "DI" And .Cells(i, 14) <> "DO" And .Cells(i, 14) <> "DT" And .Cells(i, 14) <> "EC" And .Cells(i, 14) <> "EN" And .Cells(i, 14) <> "FM" And .Cells(i, 14) <> "HD" And .Cells(i, 14) <> "LB" And .Cells(i, 14) <> "MG" And .Cells(i, 14) <> "MS" And .Cells(i, 14) <> "OD" And .Cells(i, 14) <> "OT" And .Cells(i, 14) <> "PT" And .Cells(i, 14) <> "RX" And .Cells(i, 14) <> "TG" And .Cells(i, 14) <> "VC" Then
           If Len(v_error) > 0 Then
             v_error = v_error + Chr(10)
           End If
 
           v_error = v_error + "El Sub-Tipo de Servicio (Columna 14) no está dentro de las opciones válidas."
           e = e + 1
         End If
 
         If IsDate(.Cells(i, 15)) = True Then dFechaComp = .Cells(i, 15)
 
         If dFechaComp < dFechaDGII Then
            ' NCF 16
            If Len(.Cells(i, 16)) = 0 Then
              If Len(v_error) > 0 Then
                v_error = v_error + Chr(10)
              End If
 
              v_error = v_error + "El NCF es obligatorio."
              e = e + 1
 
            ElseIf IsNumeric(Mid(.Cells(i, 16), 1, 1)) = True Or IsNumeric(Mid(.Cells(i, 16), 2)) = False Then
              If Len(v_error) > 0 Then
                v_error = v_error + Chr(10)
              End If
 
              v_error = v_error + "NCF (Columna #16) Incorrecto."
              e = e + 1
 
            ElseIf (Mid(.Cells(i, 16), 1, 1) = "B") Then
              If Len(v_error) > 0 Then
                v_error = v_error + Chr(10)
              End If
 
              v_error = v_error + "El NCF debe ser Tipo A (Columna #16), el Tipo B no está vigente para la fecha del NCF Indicado."
              e = e + 1
 
            ElseIf Len(.Cells(i, 16)) <> 19 Then
              If Len(v_error) > 0 Then
                v_error = v_error + Chr(10)
              End If
 
              v_error = v_error + "NCF (Columna #16) con Longitud Invalida"
              e = e + 1
 
            ElseIf (Mid(.Cells(i, 16), 1, 1) <> "A" And Mid(.Cells(i, 16), 1, 1) <> "P") Or (Mid(.Cells(i, 16), 10, 2) <> "01" And Mid(.Cells(i, 16), 10, 2) <> "03" And Mid(.Cells(i, 16), 10, 2) <> "04") Then
              If Len(v_error) > 0 Then
                v_error = v_error + Chr(10)
              End If
 
              v_error = v_error + " NCF (Columna #16) con Formato Invalido."
              e = e + 1
            End If
        Else
            ' NCF 16
            If Len(.Cells(i, 16)) = 0 Then
              If Len(v_error) > 0 Then
                v_error = v_error + Chr(10)
              End If
 
              v_error = v_error + "El NCF es obligatorio."
              e = e + 1
 
            ElseIf IsNumeric(Mid(.Cells(i, 16), 1, 1)) = True Or IsNumeric(Mid(.Cells(i, 16), 2)) = False Then
              If Len(v_error) > 0 Then
                v_error = v_error + Chr(10)
              End If
 
              v_error = v_error + "NCF (Columna #16) Incorrecto."
              e = e + 1
 
            ElseIf (Mid(.Cells(i, 16), 1, 1) = "A") Then
              If Len(v_error) > 0 Then
                v_error = v_error + Chr(10)
              End If
 
              v_error = v_error + "El NCF debe ser Tipo B (Columna #16), el Tipo A no es válido para la fecha del NCF Indicado."
              e = e + 1
 
            ElseIf (Mid(.Cells(i, 16), 1, 1) <> "B") Or (Mid(.Cells(i, 16), 2, 2) <> "01" And Mid(.Cells(i, 16), 2, 2) <> "03" And Mid(.Cells(i, 16), 2, 2) <> "04") Then
              If Len(v_error) > 0 Then
                v_error = v_error + Chr(10)
              End If
 
              v_error = v_error + "NCF Tipo B (Columna #16) con Formato Invalido."
              e = e + 1
 
            ElseIf Len(.Cells(i, 16)) <> 11 Then
              If Len(v_error) > 0 Then
                v_error = v_error + Chr(10)
              End If
 
              v_error = v_error + "NCF Tipo B (Columna #16) con Longitud Invalida."
              e = e + 1
            End If
        End If
 
         ' Fecha NCF
         If Len(.Cells(i, 15)) = 0 Then
           If Len(v_error) > 0 Then
             v_error = v_error + Chr(10)
           End If
 
           v_error = v_error + "La Fecha NCF (Columna #15) es obligatoria."
           e = e + 1
         ElseIf IsDate(.Cells(i, 15)) = False Then
           If Len(v_error) > 0 Then
             v_error = v_error + Chr(10)
           End If
 
           v_error = v_error + "La Fecha NCF (Columna #15) no tiene un formato valido."
           e = e + 1
         End If
 
         ' Tipo de Comprobante
         .Cells(i, 17) = UCase(.Cells(i, 17))
 
        If dFechaComp < dFechaDGII Then
            ' Asignacion Automatica Tipo segun Estructura de NCF
            If Mid(.Cells(i, 16), 10, 2) = "01" Then
              Cells(i, 17) = "F"
            ElseIf Mid(.Cells(i, 16), 10, 2) = "03" Then
              Cells(i, 17) = "D"
            ElseIf Mid(.Cells(i, 16), 10, 2) = "04" Then
              Cells(i, 17) = "C"
            End If
         Else
            ' Asignacion Automatica Tipo segun Estructura de NCF
            If Mid(.Cells(i, 16), 2, 2) = "01" Then
              Cells(i, 17) = "F"
            ElseIf Mid(.Cells(i, 16), 2, 2) = "03" Then
              Cells(i, 17) = "D"
            ElseIf Mid(.Cells(i, 16), 2, 2) = "04" Then
              Cells(i, 17) = "C"
            End If
         End If
 
         If Len(.Cells(i, 17)) = 0 Then
           If Len(v_error) > 0 Then
             v_error = v_error + Chr(10)
           End If
 
           v_error = v_error + "El Tipo de Comprobante (Columna #17) es obligatorio."
           e = e + 1
         ElseIf .Cells(i, 17) <> "F" And .Cells(i, 17) <> "D" And .Cells(i, 17) <> "C" Then
           If Len(v_error) > 0 Then
             v_error = v_error + Chr(10)
           End If
 
           v_error = v_error + "El Tipo de Comprobante (Columna #17) no está dentro de las opciones válidas."
           e = e + 1
         End If
 
         If (.Cells(i, 17) = "D" Or .Cells(i, 17) = "C") And Len(.Cells(i, 19)) = 0 Then
           If Len(v_error) > 0 Then
             v_error = v_error + Chr(10)
           End If
 
           v_error = v_error + "El NCF Modificado (Columna #19) es obligatorio para las Notas de Débito y Crédito."
           e = e + 1
         End If
 
         If Mid(.Cells(i, 19), 1, 1) = "A" Then
            If (.Cells(i, 17) = "D" Or .Cells(i, 17) = "C") And (IsNumeric(Mid(.Cells(i, 19), 1, 1)) = True Or IsNumeric(Mid(.Cells(i, 19), 2)) = False) Then
              If Len(v_error) > 0 Then
                v_error = v_error + Chr(10)
              End If
 
              v_error = v_error + "NCF Modificado (Columna #19) Incorrecto."
              e = e + 1
 
            ElseIf (.Cells(i, 17) = "D" Or .Cells(i, 17) = "C") And Len(.Cells(i, 19)) <> 19 Then
              If Len(v_error) > 0 Then
                v_error = v_error + Chr(10)
              End If
 
              v_error = v_error + "NCF Modificado (Columna #19) con Longitud Invalida."
              e = e + 1
 
            ElseIf (.Cells(i, 17) = "D" Or .Cells(i, 17) = "C") And ((Mid(.Cells(i, 19), 1, 1) <> "A" And Mid(.Cells(i, 19), 1, 1) <> "P") Or Mid(.Cells(i, 19), 10, 2) <> "01") Then
              If Len(v_error) > 0 Then
                v_error = v_error + Chr(10)
              End If
 
              v_error = v_error + "NCF Modificado (Columna #19) con Formato Invalido."
              e = e + 1
            End If
        Else
            If (.Cells(i, 17) = "D" Or .Cells(i, 17) = "C") And (IsNumeric(Mid(.Cells(i, 19), 1, 1)) = True Or IsNumeric(Mid(.Cells(i, 19), 2)) = False) Then
              If Len(v_error) > 0 Then
                v_error = v_error + Chr(10)
              End If
 
              v_error = v_error + "NCF Modificado (Columna #19) Incorrecto."
              e = e + 1
 
            ElseIf (.Cells(i, 17) = "D" Or .Cells(i, 17) = "C") And Len(.Cells(i, 19)) <> 11 Then
              If Len(v_error) > 0 Then
                v_error = v_error + Chr(10)
              End If
 
              v_error = v_error + "NCF Modificado (Columna #19) con Longitud Invalida."
              e = e + 1
 
            ElseIf (.Cells(i, 17) = "D" Or .Cells(i, 17) = "C") And ((Mid(.Cells(i, 19), 1, 1) <> "B") Or Mid(.Cells(i, 19), 2, 2) <> "01") Then
              If Len(v_error) > 0 Then
                v_error = v_error + Chr(10)
              End If
 
              v_error = v_error + "NCF Modificado (Columna #19) con Formato Invalido."
              e = e + 1
            End If
        End If
 
        ' Monto Nota Debito/Credito
         If (.Cells(i, 17) = "D" Or .Cells(i, 17) = "C") And Len(.Cells(i, 20)) = 0 Then
           If Len(v_error) > 0 Then
             v_error = v_error + Chr(10)
           End If
 
           v_error = v_error + "El Monto NC y/o ND (Columna #20) es obligatorio para las Notas de Débito y Crédito."
           e = e + 1
         ElseIf Len(.Cells(i, 20)) > 0 And IsNumeric(.Cells(i, 20)) = False Then
           If Len(v_error) > 0 Then
             v_error = v_error + Chr(10)
           End If
 
           v_error = v_error + "El Monto NC y/o ND (Columna #20) solamente puede ser numérico."
           e = e + 1
         End If
 
         ' Fecha Vencimiento NCF
         If dFechaComp >= dFechaDGII Then
            If Len(.Cells(i, 18)) = 0 Then
              If Len(v_error) > 0 Then
                v_error = v_error + Chr(10)
              End If
 
              v_error = v_error + "Para la Fecha de NCF Indicada, la Fecha de Vencimiento del NCF (Columna #18) es obligatoria."
              e = e + 1
            ElseIf IsDate(.Cells(i, 18)) = False Then
              If Len(v_error) > 0 Then
                v_error = v_error + Chr(10)
              End If
 
              v_error = v_error + "La Fecha Vencimiento NCF (Columna #18) no tiene un formato valido."
              e = e + 1
 
             ElseIf .Cells(i, 18) < dFechaComp Then
              If Len(v_error) > 0 Then
                v_error = v_error + Chr(10)
              End If
 
              v_error = v_error + "La Fecha Vencimiento NCF (Columna #18) No debe ser menor a la fecha del Comprobante."
              e = e + 1
            End If
         End If
 
 
         .Cells(2, 10) = i - 8 + 1    'JADB: Se cambio por un CountA
         .Cells(i, 27) = v_error
         Worksheets("data").Cells(4, 10) = e
         .Cells(4, 10) = e   'JADB: Se cambio por un CountA
         '
         '
         ' Pon las lineas con error en color rojo
         If Len(.Cells(i, 27)) > 0 Then
           With .Range("A" & CStr(i) & ":AA" & CStr(i)).Font
            .Color = -16776961
            .TintAndShade = 0
          End With
         End If
         '
      Next i
     .EnableAutoFilter = True
     .Protect Password:="humsal", contents:=True, userInterfaceOnly:=True
      Exit Sub
    End If
  End With
 
ErrorHandler:
  e = e + 1
  Worksheets("data").Unprotect Password:="humsal"
  'Worksheets("data").Cells(4, 10) = e
  'Worksheets("data").Cells(i, 27) = "Error de estructura en columna por formato no soportado."
  Worksheets("data").EnableAutoFilter = True
  Worksheets("data").Protect Password:="humsal", contents:=True, userInterfaceOnly:=True
  Resume Next
End Sub
 
' Validar archivo
Private Sub CommandButton1_Click()
  ValidaArchivo
 
  If Worksheets("data").Cells(4, 29) = -1 Then
     MsgBox ("Archivo Validado Con Error!")
     Exit Sub
  End If
 
  '
  e = Worksheets("data").Cells(4, 10)
  If Worksheets("data").Cells(4, 10) = 0 Then
      MsgBox ("Archivo Validado Sin Errores !")
  Else
      MsgBox ("Archivo Validado Con " & CStr(e) & " Error(es). Verifique la columna Inconsistencias !")
  End If
End Sub
 
' Generar archivo
Private Sub CommandButton2_Click()
 
    'Ejecuta la validacion antes de generar el archivo
    'ValidaArchivo
 
    'If Worksheets("data").Cells(4, 29) = -1 Then
    '  MsgBox ("El Código (Columna B4) o el nombre (Columna D4) del Reclamante debe ser especificado. Complete la información requerida y proceda a generar.")
    '  Exit Sub
    'End If
 
    If Worksheets("data").Cells(2, 10) = 0 Then
      MsgBox "No hay líneas validadas para generar el archivo de texto. Complete la información requerida y proceda a Validar."
      Exit Sub
    End If
 
    If Worksheets("data").Cells(4, 10) > 0 Then
      MsgBox "No es posible generar el archivo debido a que se encontraron Errores de Validación. Debe corregirlos y Validar nuevamente."
      Exit Sub
    End If
 
    Dim sPath As String
 
    sPath = Application.GetSaveAsFilename("", "Text Files,*.txt")
    If LCase$(sPath) = "false" Then Exit Sub
     'specify the widths of our fields
     'the number of columns is the number specified in the line below +1
    Dim s(30) As Integer
    Dim a(30) As String
    Dim t(30) As String
 
     'starting at 0 specify the width of each column
'Referencia ARS  1   0
s(0) = 15
a(0) = L
t(0) = "A"
 
'Fecha Servicio  2   1
s(1) = 6
a(1) = L
t(1) = "A"
 
'Afiliado    3   2
s(2) = 20
a(2) = L
t(2) = "A"
 
'Nombre Afiliado 4   3
s(3) = 160
a(3) = L
t(3) = "A"
 
'Cedula  5   4
s(4) = 11
a(4) = L
t(4) = "A"
 
'Total Reclamado 6   5
s(5) = 12
a(5) = R
t(5) = N
 
'Monto Servicio  7   6
s(6) = 12
a(6) = R
t(6) = N
 
'Monto Bien  8   7
s(7) = 12
a(7) = R
t(7) = N
 
'Total a Pagar   9   8
s(8) = 12
a(8) = R
t(8) = N
 
'Total Afiliado  10  9
s(9) = 12
a(9) = R
t(9) = N
 
'Factura PSS 11  10
s(10) = 20
a(10) = L
t(10) = "A"
 
'Fecha Factura PSS   12  11
s(11) = 6
a(11) = L
t(11) = "A"
 
'Tipo Servicio   13  12
s(12) = 3
a(12) = L
t(12) = "A"
 
'Subtipo Servicio    14  13
s(13) = 2
a(13) = L
t(13) = "A"
 
'Fecha NCF   15  14
s(14) = 6
a(14) = L
t(14) = "A"
 
'NCF 16  15
s(15) = 19
a(15) = L
t(15) = "A"
 
'Tipo Comprobante    17  16
s(16) = 2
a(16) = L
t(16) = "A"
 
'Fecha Venc. NCF 18  17
s(17) = 6
a(17) = L
t(17) = "A"
 
'NCF Modificado  19  18
s(18) = 19
a(18) = L
t(18) = "A"
 
'Monto ND/NC 20  19
s(19) = 12
a(19) = R
t(19) = N
 
'Monto ITBIS 21  20
s(20) = 12
a(20) = R
t(20) = N
 
'Monto ISC   22  21
s(21) = 12
a(21) = R
t(21) = N
 
'Monto Otros Imp 23  22
s(22) = 12
a(22) = R
t(22) = N
 
'Telefono    24  23
s(23) = 20
a(23) = L
t(23) = "A"
 
'Celular 25  24
s(24) = 20
a(24) = L
t(24) = "A"
 
'Email   26  25
s(25) = 60
a(25) = L
t(25) = "A"
 
    'wri    te to file the data from the activesheet
    CreateFixedWidthFile sPath, ActiveSheet, s, a, t
 
    MsgBox ("Archivo Generado Exitosamente")
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
Imágen de perfil de Andres Leonardo
Val: 3.117
Oro
Ha mantenido su posición en Visual Basic (en relación al último mes)
Gráfica de Visual Basic

Excell microsoft visual basic error 13 en tiempo de ejecucion

Publicado por Andres Leonardo (1798 intervenciones) el 09/11/2018 14:50:27
es que quieres hacer un replace en algo que no parece ser un string

en este caso utiliza un format directamente sin el replace.

luego ya que es un string lo reemplazas

Saludos
otra manera de quitar comas o puntoses multiplicar * 100 el valor.....


strcell = Format(ws.Cells(i, j + 1).Value, "###,00")
strcell = Replace(strcell, ",", "")

o la que intentas
strcell = Replace(Format(ws.Cells(i, j + 1).Value, "###,00"), ",", "")
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