problema al copiar datos de una hoja y pegarlos como valores en otra
Publicado por Agr (1 intervención) el 19/08/2020 18:51:13
Buenos dias tengo un libro de excel que copia un rango de celas y las pega como valores en otra hoja, la mayoria de las veces funciona bien pero el problema es que de vez en cuando me da un error y despues de darle en depurar y detener la macro, el archivo se cierra automaticamente, ojala me puedan ayudar
En las imagenes adjuntas, la hoja color verdes es la hoja principal de donde quiero copiar los datos
En las imagenes adjuntas, la hoja color verdes es la hoja principal de donde quiero copiar los datos
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
Dim a As Boolean
Sub finaliza()
a = False
End Sub
Sub vender()
Dim f, t As Date
Dim finl, finventa, finventa2, nv, ncliente, m As Integer
Dim cliente, cajero As String
Dim hprincipal As Excel.Worksheet, _
hventa As Excel.Worksheet
Set hprincipal = Worksheets("Principal")
Set hventa = Worksheets("ventas")
a = True
hprincipal.Select
If Range("C6") = "" Then
MsgBox "DEBES SELECCIONAR AL MENOS UN PRODUCTO", , "Agropecuaria Lestayc"
Else
If Range("D3") = "" Then
MsgBox "DEBES SELECCIONAR A UN CLIENTE", , "Agropecuaria Lestayc"
Else
If Range("E3") = "" Then
MsgBox "DEBES SELECCIONAR QUIEN ATIENDE LA VENTA", , "Agropecuaria Lestayc"
Else
frm_finventa.Show
If a = True Then
r = hventa.Range("e2")
If r = "" Then
finventa = 2
Else
finventa = hventa.Range("d" & Rows.Count).End(xlUp).Row + 1
End If
fin1 = hprincipal.Range("c" & Rows.Count).End(xlUp).Row
hprincipal.Range("c6:i" & fin1).Copy
hventa.Range("d" & finventa).PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Application.CutCopyMode = False
finventa2 = hventa.Range("d" & Rows.Count).End(xlUp).Row
f = Date
nv = hprincipal.Range("h3")
t = Time
ncliente = hprincipal.Range("b3")
cliente = hprincipal.Range("d3")
cajero = hprincipal.Range("e3")
dif = finventa2 - finventa
With hventa
If dif = 0 Then
.Cells(finventa, 2) = f
.Cells(finventa, 1) = nv
.Cells(finventa, 3) = t
.Cells(finventa, 11) = ncliente
.Cells(finventa, 12) = cliente
.Cells(finventa, 13) = cajero
Else
.Range(.Cells(finventa, 2), .Cells(finventa2, 2)) = f
.Range(.Cells(finventa, 1), .Cells(finventa2, 1)) = nv
.Range(.Cells(finventa, 3), .Cells(finventa2, 3)) = t
.Range(.Cells(finventa, 11), .Cells(finventa2, 11)) = ncliente
.Range(.Cells(finventa, 12), .Cells(finventa2, 12)) = cliente
.Range(.Cells(finventa, 13), .Cells(finventa2, 13)) = cajero
End If
End With
hprincipal.Select
Range("c6:c20").ClearContents
Range("e6:e20").ClearContents
Range("f6:f20").ClearContents
Range("d3").Select
hventa.Range("o1") = nv + 1
ThisWorkbook.Save
MsgBox "LA VENTA SE GUARDO CORRECTAMENTE", , "Agropecuaria Lestayc"
End If
End If
End If
End If
End Sub
Valora esta pregunta
-1