Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,355
Default Adding formula to multiple workbooks

I have multiple workbooks in the same folder and I want to add a formula from
cell B2 to the end of the data listed in column A. The formula would be the
same for all workbooks. How would I do this with VBA?

Thanks,

Barb Reinhardt
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Adding formula to multiple workbooks

set rng = Range(cells(2,1),cells(2,1).end(xldown))
rng.offset(0,1).Formula = "=A2^.5"

would be the basic code.
--
Regards,
Tom Ogilvy

"Barb Reinhardt" wrote in message
...
I have multiple workbooks in the same folder and I want to add a formula

from
cell B2 to the end of the data listed in column A. The formula would be

the
same for all workbooks. How would I do this with VBA?

Thanks,

Barb Reinhardt



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,355
Default Adding formula to multiple workbooks

How would I open each workbook to add it?

"Tom Ogilvy" wrote:

set rng = Range(cells(2,1),cells(2,1).end(xldown))
rng.offset(0,1).Formula = "=A2^.5"

would be the basic code.
--
Regards,
Tom Ogilvy

"Barb Reinhardt" wrote in message
...
I have multiple workbooks in the same folder and I want to add a formula

from
cell B2 to the end of the data listed in column A. The formula would be

the
same for all workbooks. How would I do this with VBA?

Thanks,

Barb Reinhardt




  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Adding formula to multiple workbooks

Seems like you asked this a while ago, but perhaps not

Dim sPath as String
Dim sName as String
Dim bk as Workbook
Dim sh as Worksheet
Dim rng as Range
sPath = "C:\Myfolder1\Myfolder2\"
sName = dir(sPath & "*.xls")
do while sName < ""
set bk = Workbooks.Open(sPath & sname)
for each sh in bk.worksheets
set rng = sh.Range(sh.cells(2,1),sh.cells(2,1).end(xldown))
rng.offset(0,1).Formula = "=A2^.5"
next
bk.close Savechanges:=True
sname = Dir()
Loop

if you only are going to work on a single specific sheet, adjust the code to
reflect that.
set sh = bk.Worksheets(1)
set rng = sh.Range(sh.cells(2,1),sh.cells(2,1).end(xldown))
rng.offset(0,1).Formula = "=A2^.5"
bk.close Savechanges:=True
--
Regards,
Tom Ogilvy


"Barb Reinhardt" wrote in message
...
I have multiple workbooks in the same folder and I want to add a formula

from
cell B2 to the end of the data listed in column A. The formula would be

the
same for all workbooks. How would I do this with VBA?

Thanks,

Barb Reinhardt



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,355
Default Adding formula to multiple workbooks

I may have asked a similar question, but I'm still REAL fuzzy on VBA.
Thanks for humoring me. :)

Barb

"Tom Ogilvy" wrote:

Seems like you asked this a while ago, but perhaps not

Dim sPath as String
Dim sName as String
Dim bk as Workbook
Dim sh as Worksheet
Dim rng as Range
sPath = "C:\Myfolder1\Myfolder2\"
sName = dir(sPath & "*.xls")
do while sName < ""
set bk = Workbooks.Open(sPath & sname)
for each sh in bk.worksheets
set rng = sh.Range(sh.cells(2,1),sh.cells(2,1).end(xldown))
rng.offset(0,1).Formula = "=A2^.5"
next
bk.close Savechanges:=True
sname = Dir()
Loop

if you only are going to work on a single specific sheet, adjust the code to
reflect that.
set sh = bk.Worksheets(1)
set rng = sh.Range(sh.cells(2,1),sh.cells(2,1).end(xldown))
rng.offset(0,1).Formula = "=A2^.5"
bk.close Savechanges:=True
--
Regards,
Tom Ogilvy


"Barb Reinhardt" wrote in message
...
I have multiple workbooks in the same folder and I want to add a formula

from
cell B2 to the end of the data listed in column A. The formula would be

the
same for all workbooks. How would I do this with VBA?

Thanks,

Barb Reinhardt






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
Formula for adding a cell in multiple workbooks PaPr Excel Worksheet Functions 1 February 3rd 10 09:31 PM
Adding a Row to Multiple Workbooks LPS Excel Discussion (Misc queries) 0 May 31st 07 05:04 PM
Adding multiple workbooks together Keith Excel Discussion (Misc queries) 1 August 8th 05 09:39 PM
adding certain cells in multiple worksheets in multiple workbooks Stephen via OfficeKB.com Excel Worksheet Functions 1 February 4th 05 08:31 PM
Adding cells from multiple workbooks Blackcat Excel Discussion (Misc queries) 6 January 19th 05 09:50 AM


All times are GMT +1. The time now is 01:53 PM.

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

About Us

"It's about Microsoft Excel"