View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.programming
Barb Reinhardt Barb Reinhardt is offline
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