Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 45
Default Inserting rows macro

Hi,
I have this code, as below, coming from David McRitchie´s webpage. It works
great, (Thanks, David), but I need help to extend it, so that it works for
my needs.

Now, I have a workbook with several simular sheets. It´s one sheet for every
month of the year and some other sheets.
In each "monthsheet" I have formulas that refers to one "main sheet" that
contains all the information to be .

I wonder if you can help me to create a macro that always starts in the
"main sheet" and then inserts the same rows in all the other sheets at the
same time, and also change the formulas from (i.e =c6 to =c7), and not as
the formula is now, as it just duplicates. (i.e=c6 to =c6). All the sheets
are protected with password, therefore I´ts also necessary to unprotect, and
then protect the sheets in that same code.

I hope you understand what I´m trying to reach for.

Code:

Sub InsertRowsAndFillFormulas(Optional vRows As Long)
' Documented: http://www.mvps.org/dmcritchie/excel/insrtrow.htm
' Insert Rows -- 1997/09/24 Mark Hill
'Dim vRows As Integer
' row selection based on active cell -- rev. 2000-09-02 David McRitchie
ActiveCell.EntireRow.Select 'So you do not have to preselect entire row
If vRows < 1 Then
vRows = Application.InputBox(prompt:= _
"How many rows do you want to add?", Title:="Add Rows", _
Default:=1, Type:=1) '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. 20001-01-17 Gary L. Brown, programming, Grouped sheets
Dim sht As Worksheet, shts() As String, i As Integer
ReDim shts(1 To Worksheets.Application.ActiveWorkbook. _
Windows(1).SelectedSheets.Count)
i = 0
For Each sht In _
Application.ActiveWorkbook.Windows(1).SelectedShee ts
Sheets(sht.Name).Select
i = i + 1
shts(i) = sht.Name

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

//Regards,
Thomas


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Inserting rows macro

Hi Jonsson
Provided that you want to insert a row at the same place on ALL you
worksheets, you could use the following code.

'Select multiple worksheets.
Sheets(Array("Sheet1", "Sheet2", "Sheet3")).Select

Select and insert the row that you wish
Sheets("Sheet1").Activate
Rows("3:3").Select
Selection.Insert Shift:=xlDown

One row has been inserted into each of the worksheets.
Hope this help

--
Message posted from http://www.ExcelForum.com

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Macro auto inserting rows and formulas jjoverfield Excel Discussion (Misc queries) 0 November 13th 08 10:51 PM
Macro Help- Inserting Blank Rows jack Excel Discussion (Misc queries) 3 January 16th 07 09:43 PM
Inserting Blank Rows Macro? Michael Saffer Excel Worksheet Functions 2 November 9th 04 06:23 PM
Inserting Rows Through a Macro Mike[_56_] Excel Programming 3 October 8th 03 03:52 AM
INSERTING ROWS WITH A MACRO Jay Dean Excel Programming 15 September 16th 03 05:08 PM


All times are GMT +1. The time now is 06:03 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"