Foros del Web » Soporte técnico » Ofimática »

macro de excel!!

Estas en el tema de macro de excel!! en el foro de Ofimática en Foros del Web. hola tengo una macro que no puedo hacer! mi programacion en visual basic y mi logica asi como conocimiento de las estructuras de control no ...
  #1 (permalink)  
Antiguo 23/03/2009, 10:18
 
Fecha de Ingreso: marzo-2009
Mensajes: 7
Antigüedad: 15 años, 1 mes
Puntos: 0
macro de excel!!

hola tengo una macro que no puedo hacer! mi programacion en visual basic y mi logica asi como conocimiento de las estructuras de control no es mala, el problema es que no se como hacer referencia o manejar pues al celdas de excel. explico: se tiene un archivo en excel con encabezados por ediciones 1, 2, 3, 4, etc y cada mes se añade una nueva edicion. de estos encabezados, cada edicion tiene 3 columnas: envio, venta y porcentaje de venta (que es la division entre venta y envio)
1. se busca que encuentre la ultima edicion añadida (es decir, las ultimas 3 columnas de la hoja - envio, venta y %)
2. ya que tenga estas 3 ultimas columnas que tome el porcentaje de venta y si el porcentaje es 0%, que cuente y sume los valores de la columna de envio y sume los valores de la columna de venta pero que correspondan a la fila del porcentaje 0
por favor me urge llevo intentos malisimos, porque aunque tengo la logica de los ifs, whiles, cases y los operadores, no se como manipular los rangos de la hoja de excel!
  #2 (permalink)  
Antiguo 24/03/2009, 11:21
Avatar de mrocf  
Fecha de Ingreso: marzo-2007
Ubicación: Bs.As.
Mensajes: 1.103
Antigüedad: 17 años, 1 mes
Puntos: 88
macro de excel!!

La verdad es que no está demasiado clara la descripción de la estructura de datos de tu archivo.

Te sugiero que "armes" un "archivito auxiliar" con dos hojas: en la primera muestra como están distribuídos tus datos (situación inicial); y en la segunda hoja, como deseas que queden las cuentas y cálculos solicitados incluyendo todos los cálculos que consideres pertinentes.

Saludos, Cacho.
  #3 (permalink)  
Antiguo 21/04/2009, 09:36
 
Fecha de Ingreso: marzo-2009
Mensajes: 7
Antigüedad: 15 años, 1 mes
Puntos: 0
Respuesta: macro de excel!!

ya quedo el codigo solo que me mark algunos errores al usarlo en otro archivo, es decir si lo uso en el archivo en el que la hice no hay problema, pero al querer usarla en otro libro (que es el punto de la macro) ma mark error 13. aqui pongo el codigo de la macro, advierto que mi programacion es malisima por lo que hice lo que pude:
'acceso directo ctrl + i
Sub general()
Dim fila1 As Integer, fila As Integer, uc As Integer, uf As Integer
Dim tot1 As Long, tot2 As Long, tot3 As Long, tot4 As Long
Dim pv1 As Long, pv2 As Long, pv3 As Long, pv4 As Long
Dim v1 As Long, v2 As Long, v3 As Long, v4 As Long
Dim ec1 As Long, ec2 As Long, ec3 As Long, ec4 As Long
Dim pvc1 As Long, pvc2 As Long, pvc3 As Long, pvc4 As Long
Dim vc1 As Long, vc2 As Long, vc3 As Long, vc4 As Long
Dim el1 As Long, el2 As Long, el3 As Long, el4 As Long
Dim pvl1 As Long, pvl2 As Long, pvl3 As Long, pvl4 As Long
Dim vl1 As Long, vl2 As Long, vl3 As Long, vl4 As Long
Dim el21 As Long, el22 As Long, el23 As Long, el24 As Long
Dim pvl21 As Long, pvl22 As Long, pvl23 As Long, pvl24 As Long
Dim vl21 As Long, vl22 As Long, vl23 As Long, vl24 As Long
Dim elt1 As Long, elt2 As Long, elt3 As Long, elt4 As Long
Dim pvlt1 As Long, pvlt2 As Long, pvlt3 As Long, pvlt4 As Long
Dim vlt1 As Long, vlt2 As Long, vlt3 As Long, vlt4 As Long
fila1 = 6
Sheets(1).Activate
'busca la ultima columna
If WorksheetFunction.CountA(Cells) > 0 Then
uc = Cells.Find(what:="*", after:=[a1], searchorder:=xlByColumns, searchdirection:=xlPrevious).Column
End If
'busca la ultima fila
If WorksheetFunction.CountA(Cells) > 0 Then
uf = Cells.Find(what:="*", after:=[a1], searchorder:=xlByRows, searchdirection:=xlPrevious).Row
End If
'busca operaciones invalidas y deja en blanco la celda
For fila = fila1 To uf - 1
If IsError(Cells(fila, uc).Value) Then
If Cells(fila, uc).Value = CVErr(xlErrDiv0) Then
Cells(fila, uc).Value = ""
End If
End If
Next fila
'busca rangos para hacer las sumas de todo (General)
For fila = fila1 To uf - 1
If Cells(fila, uc).Value <= 0 Then
If Not IsEmpty(Cells(fila, uc).Value) Then
tot1 = tot1 + Cells(fila, uc - 4)
pv1 = pv1 + 1
v1 = v1 + Cells(fila, uc - 1)
End If
Else
If Cells(fila, uc).Value >= 0.01 And Cells(fila, uc).Value <= 0.494 Then
If Not IsEmpty(Cells(fila, uc).Value) Then
tot2 = tot2 + Cells(fila, uc - 4)
pv2 = pv2 + 1
v2 = v2 + Cells(fila, uc - 1)
End If
Else
If Cells(fila, uc).Value >= 0.495 And Cells(fila, uc).Value < 0.705 Then
If Not IsEmpty(Cells(fila, uc).Value) Then
tot3 = tot3 + Cells(fila, uc - 4)
pv3 = pv3 + 1
v3 = v3 + Cells(fila, uc - 1)
End If
Else
If Cells(fila, uc).Value > 0.7055 Then
If Not IsEmpty(Cells(fila, uc).Value) Then
'tot4 = tot4 + Cells(fila, uc - 4) aqui marca error 13 en tiempo de ejecucion: no coinciden los tipos
pv4 = pv4 + 1
v4 = v4 + Cells(fila, uc - 1)
End If
End If
End If
End If
End If
If Cells(fila, 2).Value = 8888 Or Cells(fila, 2).Value = 1690 Or Cells(fila, 2).Value = 1670 Or Cells(fila, 2).Value = 1650 Or Cells(fila, 2).Value = 1630 Or Cells(fila, 2).Value = 1610 Or Cells(fila, 2).Value = 1490 Or Cells(fila, 2).Value = 1430 Or Cells(fila, 2).Value = 1350 Or Cells(fila, 2).Value = 1330 Or Cells(fila, 2).Value = 1310 Or Cells(fila, 2).Value = 1270 Or Cells(fila, 2).Value = 1230 Or Cells(fila, 2).Value = 1210 Or Cells(fila, 2).Value = 1190 Or Cells(fila, 2).Value = 1170 Or Cells(fila, 2).Value = 1130 Or Cells(fila, 2).Value = 1070 Or Cells(fila, 2).Value = 970 Or Cells(fila, 2).Value = 810 Or Cells(fila, 2).Value = 790 Or Cells(fila, 2).Value = 710 Or Cells(fila, 2).Value = 690 Or Cells(fila, 2).Value = 650 Or Cells(fila, 2).Value = 550 Or Cells(fila, 2).Value = 530 Or Cells(fila, 2).Value = 490 Or Cells(fila, 2).Value = 470 Or Cells(fila, 2).Value = 450 Or Cells(fila, 2).Value = 390 Or Cells(fila, 2).Value = 350 Or Cells(fila, 2).Value = 90 Then
If Cells(fila, uc).Value <= 0 Then
If Not IsEmpty(Cells(fila, uc).Value) Then
ec1 = ec1 + Cells(fila, uc - 4)
pvc1 = pvc1 + 1
vc1 = vc1 + Cells(fila, uc - 1)
End If
Else
If Cells(fila, uc).Value >= 0.01 And Cells(fila, uc).Value <= 0.494 Then
If Not IsEmpty(Cells(fila, uc).Value) Then
ec2 = ec2 + Cells(fila, uc - 4)
pvc2 = pvc2 + 1
vc2 = vc2 + Cells(fila, uc - 1)
End If
Else
If Cells(fila, uc).Value >= 0.495 And Cells(fila, uc).Value < 0.705 Then
If Not IsEmpty(Cells(fila, uc).Value) Then
ec3 = ec3 + Cells(fila, uc - 4)
pvc3 = pvc3 + 1
vc3 = vc3 + Cells(fila, uc - 1)
End If
Else
If Cells(fila, uc).Value > 0.7055 Then
If Not IsEmpty(Cells(fila, uc).Value) Then
'ec4 = ec4 + Cells(fila, uc - 4) aqui marca el mismo error 13
pvc4 = pvc4 + 1
vc4 = vc4 + Cells(fila, uc - 1)
End If
End If
End If
End If
End If
End If
If Cells(fila, 2).Value = 1810 Or Cells(fila, 2).Value = 1570 Or Cells(fila, 2).Value = 1550 Or Cells(fila, 2).Value = 1510 Or Cells(fila, 2).Value = 1450 Or Cells(fila, 2).Value = 1410 Or Cells(fila, 2).Value = 1390 Or Cells(fila, 2).Value = 1370 Or Cells(fila, 2).Value = 1290 Or Cells(fila, 2).Value = 1150 Or Cells(fila, 2).Value = 1110 Or Cells(fila, 2).Value = 1050 Or Cells(fila, 2).Value = 1030 Or Cells(fila, 2).Value = 1010 Or Cells(fila, 2).Value = 990 Or Cells(fila, 2).Value = 950 Or Cells(fila, 2).Value = 930 Or Cells(fila, 2).Value = 910 Or Cells(fila, 2).Value = 890 Or Cells(fila, 2).Value = 870 Or Cells(fila, 2).Value = 850 Or Cells(fila, 2).Value = 830 Or Cells(fila, 2).Value = 770 Or Cells(fila, 2).Value = 670 Or Cells(fila, 2).Value = 610 Or Cells(fila, 2).Value = 590 Or Cells(fila, 2).Value = 570 Or Cells(fila, 2).Value = 510 Or Cells(fila, 2).Value = 430 Or Cells(fila, 2).Value = 330 Or Cells(fila, 2).Value = 310 Or Cells(fila, 2).Value = 290 Or Cells(fila, 2).Value = 270 Then
If Cells(fila, uc).Value <= 0 Then
If Not IsEmpty(Cells(fila, uc).Value) Then
el1 = el1 + Cells(fila, uc - 4)
pvl1 = pvl1 + 1
vl1 = vl1 + Cells(fila, uc - 1)
End If
Else
If Cells(fila, uc).Value >= 0.01 And Cells(fila, uc).Value <= 0.494 Then
If Not IsEmpty(Cells(fila, uc).Value) Then
el2 = el2 + Cells(fila, uc - 4)
pvl2 = pvl2 + 1
vl2 = vl2 + Cells(fila, uc - 1)
End If
Else
If Cells(fila, uc).Value >= 0.495 And Cells(fila, uc).Value < 0.705 Then
If Not IsEmpty(Cells(fila, uc).Value) Then
el3 = el3 + Cells(fila, uc - 4)
pvl3 = pvl3 + 1
vl3 = vl3 + Cells(fila, uc - 1)
End If
Else
If Cells(fila, uc).Value > 0.7055 Then
If Not IsEmpty(Cells(fila, uc).Value) Then
'el4 = el4 + Cells(fila, uc - 4) aqui tambien lo marca
pvl4 = pvl4 + 1
vl4 = vl4 + Cells(fila, uc - 1)
End If
End If
End If
End If
End If
End If
If Cells(fila, 2).Value = 250 Or Cells(fila, 2).Value = 230 Or Cells(fila, 2).Value = 210 Or Cells(fila, 2).Value = 150 Or Cells(fila, 2).Value = 130 Or Cells(fila, 2).Value = 110 Or Cells(fila, 2).Value = 70 Or Cells(fila, 2).Value = 50 Or Cells(fila, 2).Value = 30 Or Cells(fila, 2).Value = 10 Then
If Cells(fila, uc).Value <= 0 Then
If Not IsEmpty(Cells(fila, uc).Value) Then
el21 = el21 + Cells(fila, uc - 4)
pvl21 = pvl21 + 1
vl21 = vl21 + Cells(fila, uc - 1)
End If
Else
If Cells(fila, uc).Value >= 0.01 And Cells(fila, uc).Value <= 0.494 Then
If Not IsEmpty(Cells(fila, uc).Value) Then
el22 = el22 + Cells(fila, uc - 4)
pvl22 = pvl22 + 1
vl22 = vl22 + Cells(fila, uc - 1)
End If
Else
If Cells(fila, uc).Value >= 0.495 And Cells(fila, uc).Value < 0.705 Then
If Not IsEmpty(Cells(fila, uc).Value) Then
el23 = el23 + Cells(fila, uc - 4)
pvl23 = pvl23 + 1
vl23 = vl23 + Cells(fila, uc - 1)
End If
Else
If Cells(fila, uc).Value > 0.7055 Then
If Not IsEmpty(Cells(fila, uc).Value) Then
'el24 = el24 + Cells(fila, uc - 4) aqui tambien
pvl24 = pvl24 + 1
vl24 = vl24 + Cells(fila, uc - 1)
End If
End If
End If
End If
End If
End If
Next fila
End Sub
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 16:25.