Macro that copie a row and paste 500 rows

leobrice

New Member
Joined
Jun 14, 2024
Messages
37
Office Version
  1. 2013
Platform
  1. Windows
Hello friends of MrExcel good morning.
I wanted to ask for your help. Is it possible a macro that copies row 5 (A5.G5) and paste it after the last available row, taking as reference column G that has formula, about 500 rows.
NOTE: Row 5 will always be hidden
Thanks

CALCULADORA DE PRECIOS Y COSTOS DATCHEL PLUS4.xlsm
ABCDEFG
1Mi Empresa
2COSTOS DE PRODUCTOS Y SERVICIOS NACIONALES
3PRODUCTO / SERVICIONACIONALUNIDAD DE MEDIDACANTIDAD DE PRODUCTOMONTO TOTAL DE LA COMPRACOSTO PRODUCTO UNITARIO
4$$
5NACIONAL0,000
6PRODUCTO 1NACIONALFrasco10,0010.000,001.000,00por Frasco
7PRODUCTO 2NACIONALLitro2.000,00250.000,00125,00por Litro
8PRODUCTO 3NACIONALPaquete100,0045.000,00450,00por Paquete
9PRODUCTO 4NACIONALKilo12,002.600,00216,67por Kilo
10PRODUCTO 5NACIONALGalón100,00325.000,003.250,00por Galón
11PRODUCTO 6NACIONALEnvase1.500,00360.000,00240,00por Envase
12PRODUCTO 7NACIONALEnvase20.000,00650,000,03por Envase
13PRODUCTO 8NACIONALEnvase200,0010.000,0050,00por Envase
14PRODUCTO 9NACIONALEnvase150,00140.000,00933,33por Envase
15PRODUCTO 10NACIONALEnvase200,00250.000,001.250,00por Envase
16PRODUCTO 11NACIONALCaja1.500,00350.000,00233,33por Caja
17NACIONAL0,000
18NACIONAL0,000
19NACIONAL0,000
20NACIONAL0,000
21NACIONAL0,000
COSTOS PRODUCTOS NACIONALES
Cell Formulas
RangeFormula
F5:F21F5=IFERROR(E5/D5,0)
G5:G21G5=C5
B5:B21B5=$B$3
Cells with Conditional Formatting
CellConditionCell FormatStop If True
G5:G10000Cell Value=0textNO
Cells with Data Validation
CellAllowCriteria
E5:E21Any value
A5:B10000Custom=CONTAR.SI($A$5:$A$10000;A5)<=1
C5:C10000List=UNIDADES
 

Excel Facts

Excel motto
Not everything I do at work revolves around Excel. Only the fun parts.
The original file has 10,000 rows but is very heavy. What I want to do is to make a base file with 1,000 rows and then add rows (500 by 500) according to the user's need.
 
Upvote 0
@leobrice Might you be as well to have this as a table so that it automatically expands as data rows are added?
@leobrice Might you be as well to have this as a table so that it automatically expands as data rows are added?

Thank you very much @Snakehips

To be honest, I am old school, I have heard about the use of tables and their benefits but I have never applied them. I did some testing right now and it really is amazing. It does what I want without much effort,​

The question I have is the following. The workbook has 15 sheets, all with macros. Many macros have the range of 10,000 rows for execution.​

Does this change to tables affect the execution of the macros?​

I even think I can extend the range to 100,000 rows?​

Thanks​


Translated with DeepL.com (free version)
 
Upvote 0
@leobrice I would imagine that using a table should not adversely affect the function of your macros. However the only way for you to be 100% sure might be for you to do some testing with extended data?
If you do not wish to proceed with using a table then maybe something like the below will enable you to extend the formulas as and when you see fit?

VBA Code:
Sub AddRows()
Dim ws As Worksheet
Dim le As Long
Dim lf As Long
Dim rws As Long

Set ws = ActiveSheet
'last entry row determined by data in column C
le = ws.Range("C" & Rows.Count).End(xlUp).Row

'last formula row determined by data in column B
lf = ws.Range("B" & Rows.Count).End(xlUp).Row
Debug.Print le & "     " & lf
' if empty data rows greater than 10 (??)  then do nothing
If lf >= le + 10 Then Exit Sub  'edit to suit

'Otherwise Add 'rws' new Data rows
rws = 500  'edit to suit
ws.Range("A" & lf & ":G" & lf).AutoFill Destination:=ws.Range("A" & lf & ":G" & lf + rws)

Set ws = Nothing
End Sub
HTH
 
Upvote 0
Si utiliza lo anterior, elimine la línea Debug.Print.
Gracias @Snakehips
Me gustan mucho ambas opciones, incluso me inclino por las tablas, pero tengo un problema. Todas las hojas del archivo están protegidas y al parecer el proceso de autocompletar filas de tablas no funciona en hojas protegidas. Por lo que la opción de macro me funcionaría manteniendo las hojas protegidas.
Lo que me gustaria es colocar despues de la ultima fila disponible una fila avisando el fin de filas disponibles y que tendra que sumar 500 filas, entonces al ejecutar la macro esa fila bajara 500 filas y volveria a ser la ultima.

Traducido con DeepL.com (versión gratuita)

Algo como esto

EXAMPLE (2).xlsm
ABCDEFGHI
88PRODUCTO 37NACIONALKilo24,001.000,0041,67por Kilo
89PRODUCTO 38NACIONALKilo24,001.000,0041,67por Kilo
90PRODUCTO 39NACIONALKilo1,001.000,001.000,00por Kilo
91PRODUCTO 40NACIONALKilo24,001.000,0041,67por Kilo
92NACIONAL0,000
93NACIONAL0,000
94NACIONAL0,000
95NACIONAL0,000
96NACIONAL0,000
97NACIONAL0,000
98NACIONAL0,000
99NACIONAL0,000
100NACIONAL0,000
101YOU MUST ADDS MORE ROWS
COSTOS PRODUCTOS NACIONALES
Cell Formulas
RangeFormula
F88:F100F88=IFERROR(E88/D88,0)
G88:G100G88=C88
B88:B100B88=$B$3
Cells with Conditional Formatting
CellConditionCell FormatStop If True
G5:G100Cell Value=0textNO
Cells with Data Validation
CellAllowCriteria
E88:E100Any value
 
Upvote 0
If you do use the above, delete the Debug.Print line !!!
Thanks @Snakehips
I really like both options, I'm even leaning towards tables, but I have a problem. All the sheets in the file are protected and apparently the autocomplete table row process doesn't work on protected sheets. So the macro option would work for me keeping the sheets protected.
What I would like is to place after the last available row a row warning the end of available rows and that it will have to add 500 rows, then when executing the macro that row will go down 500 rows and it will be the last one again.

Translated with DeepL.com (free version)

Sorry, dont translated last post
 
Upvote 0

Forum statistics

Threads
1,223,869
Messages
6,175,088
Members
452,611
Latest member
bls2024

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top