PC Review


Reply
Thread Tools Rate Thread

Add New Row to Multiple Workbooks

 
 
=?Utf-8?B?TFBT?=
Guest
Posts: n/a
 
      31st May 2007
Using Excel 2000, I have 8 workbooks, one sheet each, which all need the same
row added to the same place in each workbook, but it could be a different
location each time the rows are added (make sense?). For example, today I
may need to add a new row 5 to all 8 workbooks, but tomorrow I may ned to add
a new row 20 to all 8 workbooks. Is there a way to do this quickly, without
having to open each one and manually add the row in?

Any help is appreciated.
--
LPS

--
LPS
 
Reply With Quote
 
 
 
 
Ron de Bruin
Guest
Posts: n/a
 
      31st May 2007
You can start with this code example
http://www.rondebruin.nl/copy4.htm
Post back if you need more help

--

Regards Ron de Bruin
http://www.rondebruin.nl/tips.htm


"LPS" <(E-Mail Removed)> wrote in message news:EE73960C-10E9-4609-AFD7-(E-Mail Removed)...
> Using Excel 2000, I have 8 workbooks, one sheet each, which all need the same
> row added to the same place in each workbook, but it could be a different
> location each time the rows are added (make sense?). For example, today I
> may need to add a new row 5 to all 8 workbooks, but tomorrow I may ned to add
> a new row 20 to all 8 workbooks. Is there a way to do this quickly, without
> having to open each one and manually add the row in?
>
> Any help is appreciated.
> --
> LPS
>
> --
> LPS

 
Reply With Quote
 
=?Utf-8?B?VG9tIE9naWx2eQ==?=
Guest
Posts: n/a
 
      31st May 2007
Sub UpdateWorkbooks()
Dim sPath as String, v as Variant
Dim bk as Workbook, i as Long
Dim ans as Variant
rw as Long

ans = Application.Inputbox("Enter the row to add",type:=1)
if ans = false then exit sub
rw = clng(ans)
sPath = "C:\Myfolder\"
v = array("Book1.xls","mybook.xls","yourbook.xls", . . .)
for i = lbound(v) to ubound(v)
set bk = workbook.Open(sPath & v(i))
bk.Worksheets(1).Rows(j).Insert
bk.Close Savechanges:=True
Next
End Sub


"LPS" wrote:

> Using Excel 2000, I have 8 workbooks, one sheet each, which all need the same
> row added to the same place in each workbook, but it could be a different
> location each time the rows are added (make sense?). For example, today I
> may need to add a new row 5 to all 8 workbooks, but tomorrow I may ned to add
> a new row 20 to all 8 workbooks. Is there a way to do this quickly, without
> having to open each one and manually add the row in?
>
> Any help is appreciated.
> --
> LPS
>
> --
> LPS

 
Reply With Quote
 
=?Utf-8?B?TFBT?=
Guest
Posts: n/a
 
      31st May 2007
Thank you for the suggestion but I know little to nothing about macros and
when I run this, the row of code "rw As Long" is highlighted and it give me
the following error:

Compile error:
Statement invalid outside Type block

Do I have to make any changes to the code before I use it?

Many thanks for your patience,
--
LPS


"Tom Ogilvy" wrote:

> Sub UpdateWorkbooks()
> Dim sPath as String, v as Variant
> Dim bk as Workbook, i as Long
> Dim ans as Variant
> rw as Long
>
> ans = Application.Inputbox("Enter the row to add",type:=1)
> if ans = false then exit sub
> rw = clng(ans)
> sPath = "C:\Myfolder\"
> v = array("Book1.xls","mybook.xls","yourbook.xls", . . .)
> for i = lbound(v) to ubound(v)
> set bk = workbook.Open(sPath & v(i))
> bk.Worksheets(1).Rows(j).Insert
> bk.Close Savechanges:=True
> Next
> End Sub
>
>
> "LPS" wrote:
>
> > Using Excel 2000, I have 8 workbooks, one sheet each, which all need the same
> > row added to the same place in each workbook, but it could be a different
> > location each time the rows are added (make sense?). For example, today I
> > may need to add a new row 5 to all 8 workbooks, but tomorrow I may ned to add
> > a new row 20 to all 8 workbooks. Is there a way to do this quickly, without
> > having to open each one and manually add the row in?
> >
> > Any help is appreciated.
> > --
> > LPS
> >
> > --
> > LPS

 
Reply With Quote
 
=?Utf-8?B?VG9tIE9naWx2eQ==?=
Guest
Posts: n/a
 
      31st May 2007
I got interrupted and sent it before I had a chance to look it over. That is
caused by a typo. You should just need to put your workbook names in inplace
of the a.xls, b.xls and change the spath= to refer to the folder where you
workbooks are located. You might want to make a dummy path and make a copy
of them there to insure the macro does what you want and doesn't screw up the
originals.

Sub UpdateWorkbooks()
Dim sPath As String, v As Variant
Dim bk As Workbook, i As Long
Dim ans As Variant
Dim rw As Long

ans = Application.InputBox("Enter the row to add", Type:=1)
If ans = False Then Exit Sub
rw = CLng(ans)
sPath = "C:\Myfolder\"
v = Array("a.xls", "b.xls", "c.xls", _
"d.xls", "e.xls", "f.xls", _
"g.xls", "h.xls")
For i = LBound(v) To UBound(v)
Set bk = Workbooks.Open(Filename:=sPath & v(i))
bk.Worksheets(1).Rows(rw).Insert
bk.Close Savechanges:=True
Next
End Sub

after making those changes, then I would expect it to run.

It should be place in a general module (in the VBE [alt+F11], Insert=>Module)

--
Regards,
Tom Ogilvy


"LPS" wrote:

> Thank you for the suggestion but I know little to nothing about macros and
> when I run this, the row of code "rw As Long" is highlighted and it give me
> the following error:
>
> Compile error:
> Statement invalid outside Type block
>
> Do I have to make any changes to the code before I use it?
>
> Many thanks for your patience,
> --
> LPS
>
>
> "Tom Ogilvy" wrote:
>
> > Sub UpdateWorkbooks()
> > Dim sPath as String, v as Variant
> > Dim bk as Workbook, i as Long
> > Dim ans as Variant
> > rw as Long
> >
> > ans = Application.Inputbox("Enter the row to add",type:=1)
> > if ans = false then exit sub
> > rw = clng(ans)
> > sPath = "C:\Myfolder\"
> > v = array("Book1.xls","mybook.xls","yourbook.xls", . . .)
> > for i = lbound(v) to ubound(v)
> > set bk = workbook.Open(sPath & v(i))
> > bk.Worksheets(1).Rows(j).Insert
> > bk.Close Savechanges:=True
> > Next
> > End Sub
> >
> >
> > "LPS" wrote:
> >
> > > Using Excel 2000, I have 8 workbooks, one sheet each, which all need the same
> > > row added to the same place in each workbook, but it could be a different
> > > location each time the rows are added (make sense?). For example, today I
> > > may need to add a new row 5 to all 8 workbooks, but tomorrow I may ned to add
> > > a new row 20 to all 8 workbooks. Is there a way to do this quickly, without
> > > having to open each one and manually add the row in?
> > >
> > > Any help is appreciated.
> > > --
> > > LPS
> > >
> > > --
> > > LPS

 
Reply With Quote
 
=?Utf-8?B?TFBT?=
Guest
Posts: n/a
 
      31st May 2007
Thank you SO much. It is working perfectly. I really appreciate the help.
--
LPS


"Tom Ogilvy" wrote:

> I got interrupted and sent it before I had a chance to look it over. That is
> caused by a typo. You should just need to put your workbook names in inplace
> of the a.xls, b.xls and change the spath= to refer to the folder where you
> workbooks are located. You might want to make a dummy path and make a copy
> of them there to insure the macro does what you want and doesn't screw up the
> originals.
>
> Sub UpdateWorkbooks()
> Dim sPath As String, v As Variant
> Dim bk As Workbook, i As Long
> Dim ans As Variant
> Dim rw As Long
>
> ans = Application.InputBox("Enter the row to add", Type:=1)
> If ans = False Then Exit Sub
> rw = CLng(ans)
> sPath = "C:\Myfolder\"
> v = Array("a.xls", "b.xls", "c.xls", _
> "d.xls", "e.xls", "f.xls", _
> "g.xls", "h.xls")
> For i = LBound(v) To UBound(v)
> Set bk = Workbooks.Open(Filename:=sPath & v(i))
> bk.Worksheets(1).Rows(rw).Insert
> bk.Close Savechanges:=True
> Next
> End Sub
>
> after making those changes, then I would expect it to run.
>
> It should be place in a general module (in the VBE [alt+F11], Insert=>Module)
>
> --
> Regards,
> Tom Ogilvy
>
>
> "LPS" wrote:
>
> > Thank you for the suggestion but I know little to nothing about macros and
> > when I run this, the row of code "rw As Long" is highlighted and it give me
> > the following error:
> >
> > Compile error:
> > Statement invalid outside Type block
> >
> > Do I have to make any changes to the code before I use it?
> >
> > Many thanks for your patience,
> > --
> > LPS
> >
> >
> > "Tom Ogilvy" wrote:
> >
> > > Sub UpdateWorkbooks()
> > > Dim sPath as String, v as Variant
> > > Dim bk as Workbook, i as Long
> > > Dim ans as Variant
> > > rw as Long
> > >
> > > ans = Application.Inputbox("Enter the row to add",type:=1)
> > > if ans = false then exit sub
> > > rw = clng(ans)
> > > sPath = "C:\Myfolder\"
> > > v = array("Book1.xls","mybook.xls","yourbook.xls", . . .)
> > > for i = lbound(v) to ubound(v)
> > > set bk = workbook.Open(sPath & v(i))
> > > bk.Worksheets(1).Rows(j).Insert
> > > bk.Close Savechanges:=True
> > > Next
> > > End Sub
> > >
> > >
> > > "LPS" wrote:
> > >
> > > > Using Excel 2000, I have 8 workbooks, one sheet each, which all need the same
> > > > row added to the same place in each workbook, but it could be a different
> > > > location each time the rows are added (make sense?). For example, today I
> > > > may need to add a new row 5 to all 8 workbooks, but tomorrow I may ned to add
> > > > a new row 20 to all 8 workbooks. Is there a way to do this quickly, without
> > > > having to open each one and manually add the row in?
> > > >
> > > > Any help is appreciated.
> > > > --
> > > > LPS
> > > >
> > > > --
> > > > LPS

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Summarizing multiple workbooks to other multiple workbooks BK Microsoft Excel Programming 0 17th May 2010 08:43 PM
Updating Workbooks from multiple links Workbooks TimJames Microsoft Excel Worksheet Functions 1 15th Dec 2007 03:34 PM
Multiple workbooks open -- closing workbooks =?Utf-8?B?SmFuZXQgUGFuaWdoZXR0aQ==?= Microsoft Excel Discussion 3 13th Nov 2007 05:43 PM
Access import Excel - multiple Worksheets from multiple Workbooks =?Utf-8?B?SW5PdmVySGVhZA==?= Microsoft Access External Data 1 21st Feb 2007 08:32 PM
macro: copy multiple workbooks to multiple tabs in single book =?Utf-8?B?TWljaGFlbA==?= Microsoft Excel Programming 0 14th Jul 2006 04:53 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 12:09 AM.