Insertar filas en una tabla mediante VBA/macros

helpdeskes

New Member
Joined
Feb 8, 2007
Messages
11
Hola a todos,
Es la primera vez que uso Mr. Excel, me resulta muy interesante la web.

El problema que no se usar las macros :confused: cuando quiero "avanzar" en conocimientos, pero no lo consigo.

Mi cuestión es la siguiente, tengo una tabla creada con 60 filas que en ciertas celdas llevan formulas (tipo referencia), entonces me gustaría crear una macro que me dijese/preguntase (tipo menú) el número de filas a insertar nuevamente a partir del última/penúltima fila (60/59) sean 5, 10, 15, etc para ampliar la tabla respetando el formato y formulas de la misma.
Mediante el grabador de macro, he podido hacer una "aproximación" pero solo seleccionado mediante COPY/PASTE sin especificar el número de filas a insertar. Claro que cuando me planteo volver a insertar más filas, no sé como especificarle cual es la última/penúltima fila de las nuevas creadas para nueva insercción de filas.

Espero haberme explicado bien y vuestra ayuda.
Millones de gracias de antemano.[/img]
 

Excel Facts

Workdays for a market open Mon, Wed, Friday?
Yes! Use "0101011" for the weekend argument in NETWORKDAYS.INTL or WORKDAY.INTL. The 7 digits start on Monday. 1 means it is a weekend.
La macro siguiente no es de mi autoria sino que figura en este link
www.mvps.org/dmcritchie/excel/insrtrow.htm


Me da la impresión de que es excelente, particularmente por lo que se conoce como "atajar errores".

Pruebala cargándola en el Modulo de la hoja donde esta tu tabla

Sub InsertRowsAndFillFormulas_caller()
'-- this macro shows on Tools, Macro..., Macros (Alt+F8) dialog
Call InsertRowsAndFillFormulas
End Sub

Sub InsertRowsAndFillFormulas(Optional vRows As Long = 0)
' Documented: http://www.mvps.org/dmcritchie/excel/insrtrow.htm
' Re: Insert Rows -- 1997/09/24 Mark Hill <markhill@charm.net.noSpam>
' row selection based on active cell -- rev. 2000-09-02 David McRitchie
Dim x as long
ActiveCell.EntireRow.Select 'So you do not have to preselect entire row
If vRows = 0 Then
vRows = Application.InputBox(prompt:= _
"How many rows do you want to add?", Title:="Add Rows", _
Default:=1, Type:=1) 'Default for 1 row, type 1 is number
If vRows = False Then Exit Sub
End If

'if you just want to add cells and not entire rows
'then delete ".EntireRow" in the following line

'rev. 2001-01-17 Gary L. Brown, programming, Grouped sheets
Dim sht As Worksheet, shts() As String, i As Long
ReDim shts(1 To Worksheets.Application.ActiveWorkbook. _
Windows(1).SelectedSheets.Count)
i = 0
For Each sht In _
Application.ActiveWorkbook.Windows(1).SelectedSheets
Sheets(sht.Name).Select
i = i + 1
shts(i) = sht.Name

x = Sheets(sht.name).UsedRange.Rows.Count 'lastcell fixup

Selection.Resize(rowsize:=2).Rows(2).EntireRow. _
Resize(rowsize:=vRows).Insert Shift:=xlDown

Selection.AutoFill Selection.Resize( _
rowsize:=vRows + 1), xlFillDefault

On Error Resume Next 'to handle no constants in range -- John McKee 2000/02/01
' to remove the non-formulas -- 1998/03/11 Bill Manville
Selection.Offset(1).Resize(vRows).EntireRow. _
SpecialCells(xlConstants).ClearContents
Next sht
Worksheets(shts).Select
End Sub
 
Upvote 0
Hola Galileogali,
Ante todo muchas gracias por tu pronta respuesto.
Tomo nota de la instrucción que me comentas, lo pruebo y te comento que tal me funcionó.
Hasta dentro de un momento.
Millones de gracias nuevamente.
 
Upvote 0
Galielogali,
Estoy aquí de nuevo, lo acabo de probar.
MUCHAS GRACIAS!!!!, por la recomendación-indicación por este modulo-macro, porque me ha funcionado PERFECTAMENTE!!!
Era esto lo que yo quería hacer, funciona muy bien.
MIL MILLONES DE GRACIAS!!!!
Saludos
 
Upvote 0

Forum statistics

Threads
1,221,418
Messages
6,159,793
Members
451,589
Latest member
Harold14

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