Macro se repita

Como puedo hacer que esta macro se repita hasta que no encuntre información 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

1 respuesta

Respuesta
1
Desconozco como te desplazas por la hoja( me refiero a si existen valores que te vayan modificando el rango a sumar) pero podría quedarte así:
Sub PruebaEsto()
Do While mi_celda <> "0"
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)"
mi_celda = ActiveCell.Value
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
Loop
End Sub
Mira a ver si te sirve
>Un saludo
>Julio
Muchas gracias ya obtuve lo que quería
Ahora lo malo es que no se como detenerla porque la suma permanece
haciendo este calculo y con la pantalla parpadeando
=SUMA(F64470:F65535) siendo que la ultima suma debe en este caso porque puede ser variable debe estar en la celda F64470 y no en la F65536
Pasalé la condición de que si la suma es 0 que finalize:
If ActiveCell.Value="0" Then Exit Sub
Pruebaló
>Un saludo
>Julio
PD: Si ya te funciona finaliza y puntúa la consulta.
Perdón me puedes ayudar por favor a insertar esa linea en la macro porque no se de programación
esa macro la fui formando de lo que grabe y de ayudas y búsquedas en distintos
foros
ya intente poner el código al final pero no me funciono
A ver si te funciona esto:
Sub PruebaEsto()
Do While mi_celda <> "0"
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)"
mi_celda = ActiveCell.Value
If ActiveCell.Value="0" Then Exit Sub
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
Loop
End Sub
Ya me contaras.
>Un saludo
>Julio
Se sigue yendo a la ultima fila de excel y sigue haciendo la suma la tengo que detener con ESC
Perdón metí la instrucción dentro del With, quedaría así:
Sub PruebaEsto()
Do While mi_celda <> "0"
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
mi_celda = ActiveCell.Value
If ActiveCell.Value="0" Then Exit Sub
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
Loop
End Sub
Mira a ver ahora.
>Un saludo
>Julio

Añade tu respuesta

Haz clic para o

Más respuestas relacionadas