ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Adding formula to multiple workbooks (https://www.excelbanter.com/excel-programming/341969-adding-formula-multiple-workbooks.html)

Barb Reinhardt

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

Tom Ogilvy

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




Barb Reinhardt

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





Tom Ogilvy

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




Barb Reinhardt

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






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

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com