Macro se repita

Como puedo hacer que esta macro se repita hasta que no encuntre informacion que sumar
Sub PruebaEsto()
Selection.End(xlDown).Select
Selection.End(xlDown).Select
Dim Rg As Range
With ActiveCell
Set Rg = Range(.Offset(-1, 0), .Offset(-1, 0).End(xlUp))
.FormulaR1C1 = "=SUM(R[-" & Rg.Rows.Count & "]C:R[-1]C)"
End With
Selection.Copy
Range(Selection, Selection.End(xlToLeft)).Select
ActiveSheet.Paste
Application.CutCopyMode = False
Selection.End(xlUp).Select
Selection.End(xlDown).Select
Selection.End(xlToRight).Select
End Sub

3 respuestas

Respuesta
1
Por ejemplo podria ser con la instruccion while
algo asi podria ser
While ActiveCell.value <> Empty
Toda tu macro va aca dentro excepto el sub proceso que con eso parte y puedes dejar el dim tambien fuera del while
Wend
Pruebalo y me comentas
me podrias ayudar por favor a acomodar las lineas ya que no se como programar
La verdad es que no entiendo mucho tu problema pero seria algo asi mucho mas simple de lo que tienes escrito:
Sub PruebaEsto()
While ActiveCell.Value <> Empty
    Selection.End(xlDown).Select
    Selection.End(xlDown).Select
    Dim Rg As Range
    With ActiveCell
    Set Rg = Range(.Offset(-1, 0), .Offset(-1, 0).End(xlUp))
    .FormulaR1C1 = "=SUM(R[-" & Rg.Rows.Count & "]C:R[-1]C)"
    End With
    Selection.Copy
    Range(Selection, Selection.End(xlToLeft)).Select
    ActiveSheet.Paste
    Application.CutCopyMode = False
    Selection.End(xlUp).Select
    Selection.End(xlDown).Select
    Selection.End(xlToRight).Select
    ActiveCell.Offset(1, 0).Select
Wend
End Sub
Sub PruebaEsto()
'Ponerse en la celda correspondiente a la suma por ejemplo
dim suma as integer
0 = suma
range("D1").select
While ActiveCell.Value <> Empty
    suma = suma + ActiveCell.Value
    Selection.Copy
    Range(Selection, Selection.End(xlToLeft)).Select
    ActiveSheet.Paste
    Application.CutCopyMode = False
    Selection.End(xlUp).Select 'Esta instruccion te lleva al principio
    Selection.End(xlDown).Select 'Esta instruccion te lleva al final
    Selection.End(xlToRight).Select 'Esta Instruccion te lleva al final Derecha
    ActiveCell.Offset(1, 0).Select
Wend
End Sub
Respuesta
1
Puedes usar Do While ... Loop
Do While ActiveCell.Value <> ""
With ActiveCell
Set Rg = Range(.Offset(-1, 0), .Offset(-1, 0).End(xlUp))
.FormulaR1C1 = "=SUM(R[-" & Rg.Rows.Count & "]C:R[-1]C)"
End With
Selection.Copy
Range(Selection, Selection.End(xlToLeft)).Select
ActiveSheet.Paste
Application.CutCopyMode = False
Loop
Hasle las mejoras y listo.
Me podrias ayudar a hacerle las correciones ya que no se programar
Crea un nuevo módulo y le insertas el código. No puedo ayudarte más porque tengo muchas consultas que resolver y también tengo muchos clientes a los que les debo cumplir.
Respuesta
1
con el Bucle While Wend
Lo que esta dentro del bucle se repite hasta que se cumpla la condicion..
Ejemplo...
El bucle dejara de realizar el prceso cuando la celda de la columna donde inicia no tenga datos..
Sub MyMacro()
Range("a1").select
While ActiveCell <> ""
If ActiveCell <> "" Then
Tu Porceso
ActiveCell.Offset(-1,0).select
End If
ActiveCell.Offset(1,0).select
Wend
End Sub
Donde Dice Tu Porceso tu vas a poner las instrcciones que tieres que se repitan...

Añade tu respuesta

Haz clic para o

Más respuestas relacionadas