PDA

View Full Version : Insert A row in workbook A automatically if a row is inserted in WOrkbook B



brindu
10-20-2009, 11:35 PM
Hello
In excel 2003 consider 12 workbooks(A-L) with 50 sheets each.The sheets are identical in all the
workbooks.When I insert a row in a sheet in workbook A I want a row to be inserted in a particular
sheet in all the other workbooks starting from B and copy the relative formuala from the previous row of
the destination to the inserted row.
This process should be repeated when a row is inserted in any of the other workbooks .
Row inserted in Workbook A ---> the process repeated for all workbooks from B-L
Row inserted in Workbook B ---> the process repeated for all workbooks from C-L
Row inserted in Workbook C ---> the process repeated for all workbooks from D-L
and so On
Please let me know how this can be done
Thanks a million in advance.

mdmackillop
10-21-2009, 05:19 AM
Welcome to VBAX
A couple of questions.

Do the new rows go in any pariculat position> ie at top, at specific Row number, or same as the inserted row?

A row inserted in C will not be inserted in A. Is that correct?

Are all the workbooks in the same folder?

brindu
10-21-2009, 10:28 AM
Thanks For the quick reply mdmackillop
The row would be inserted same as inserted row . For example In Workbook B if the row is inserted between row 31& 32 manually . Then a row has to be automatically inserted in between 31 & 32 of the following workbooks in a particular sheet in each of the sheet in the following workbooks

You are absolutely right when you say "A row inserted in C will not be inserted in A."

Yes all the work books are in the same folder.

Thanks in advance for your help.

mdmackillop
10-21-2009, 01:09 PM
This will insert the row at the selected cell, and in the subsequent workbooks in sheets of the same name.

Option Explicit
Sub AddRows()
Dim i As Long, x As Long, y As Long
Dim Arr
Dim Sh As String
Dim Rw As Long
Dim WB As Workbook
Dim Pth As String
Pth = ActiveWorkbook.Path & "\"
Sh = ActiveSheet.Name
Rw = ActiveCell.Row
If Rw = 1 Then
MsgBox "Won't work on row 1"
Exit Sub
End If
Application.ScreenUpdating = False
Arr = Array("A", "B", "C", "D")
x = Application.Match(Split(ActiveWorkbook.Name, ".")(0), Arr)
y = UBound(Arr)
ActiveCell.EntireRow.Insert
Cells(Rw - 1, 1).Resize(2).EntireRow.FillDown
For i = x To y
Set WB = Workbooks.Open(Pth & Arr(i) & ".xls")
With WB.Sheets(Sh)
.Cells(Rw, 1).EntireRow.Insert
.Cells(Rw - 1, 1).Resize(2).EntireRow.FillDown
End With
WB.Close True
Set WB = Nothing
Next
Application.ScreenUpdating = True
End Sub

brindu
10-21-2009, 10:05 PM
Thanks a lot mdmackillop. I will try out the code and get back to you . As I am new to macros I do not have a very good idea of some of the lines. Will work on it and get back to you.