Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 410
Default Change Formula on Multiple Workbooks

Here is the macro that I have and have used to change a test folder
with test workbooks. Not all of the sheets have the same same but
they are all sheet1. Can you help me amend this to have it go to
sheet1 of each workbook?

Thanks,
Jay

Sub changeFormulas()
Dim WB As Workbook
Dim fs
Dim i As Integer

Application.DisplayAlerts = False
Application.ScreenUpdating = False

Set fs = Application.FileSearch

With fs
.LookIn = "C:\Documents and Settings\JLClyde\Desktop\Steve" '
change this to the folder you want
.Filename = "*.xls"
If .Execute 0 Then ' checks to see if there are excel files
in the folder specified
For i = 1 To .FoundFiles.Count ' for each file found
fname = .FoundFiles(i) 'sets workbook name to be
opened
Set WB = Workbooks.Open(fname) 'opens the file
With WB
Sheet1.Range("B10") = "=IF(E5=0,0,E5/C10/C13)"
.Close SaveChanges:=True
End With
Next
End If
End With

Application.ScreenUpdating = True
Application.DisplayAlerts = True
End Sub
  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 35,218
Default Change Formula on Multiple Workbooks

Does this mean that you want to change the worksheet that has a codename of
Sheet1 or do you want to change the leftmost worksheet in the workbook?

If it's the leftmost worksheet, you can use:
worksheets(1).Range("B10").formula = "=IF(E5=0,0,E5/C10/C13)"

If it's the codename, you could use:

Option Explicit
Sub changeFormulas()
Dim WB As Workbook
Dim fs As FileSearch
Dim i As Long
Dim Wks As Worksheet
Dim fName As String

Application.DisplayAlerts = False
Application.ScreenUpdating = False

Set fs = Application.FileSearch

With fs
' change this to the folder you want
.LookIn = "C:\Documents and Settings\JLClyde\Desktop\Steve"
.LookIn = "C:\my documents\excel\test"
.Filename = "*.xls"
' checks to see if there are excel files in the folder specified
If .Execute 0 Then
For i = 1 To .FoundFiles.Count ' for each file found
fName = .FoundFiles(i) 'sets workbook name to be opened
Set WB = Workbooks.Open(fName) 'opens the file
With WB
Set Wks = Nothing
For Each Wks In WB.Worksheets
If LCase(Wks.CodeName) = LCase("sheet1") Then
Exit For
End If
Next Wks

If Wks Is Nothing Then
MsgBox "no sheet with a codename Sheet1 in: " _
& vbLf & WB.FullName
Else
Wks.Range("B10").Formula = "=IF(E5=0,0,E5/C10/C13)"
End If

.Close savechanges:=Not (Wks Is Nothing)
End With
Next
End If
End With

Application.ScreenUpdating = True
Application.DisplayAlerts = True
End Sub

jlclyde wrote:

Here is the macro that I have and have used to change a test folder
with test workbooks. Not all of the sheets have the same same but
they are all sheet1. Can you help me amend this to have it go to
sheet1 of each workbook?

Thanks,
Jay

Sub changeFormulas()
Dim WB As Workbook
Dim fs
Dim i As Integer

Application.DisplayAlerts = False
Application.ScreenUpdating = False

Set fs = Application.FileSearch

With fs
.LookIn = "C:\Documents and Settings\JLClyde\Desktop\Steve" '
change this to the folder you want
.Filename = "*.xls"
If .Execute 0 Then ' checks to see if there are excel files
in the folder specified
For i = 1 To .FoundFiles.Count ' for each file found
fname = .FoundFiles(i) 'sets workbook name to be
opened
Set WB = Workbooks.Open(fname) 'opens the file
With WB
Sheet1.Range("B10") = "=IF(E5=0,0,E5/C10/C13)"
.Close SaveChanges:=True
End With
Next
End If
End With

Application.ScreenUpdating = True
Application.DisplayAlerts = True
End Sub


--

Dave Peterson
  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 410
Default Change Formula on Multiple Workbooks

On Mar 24, 4:18*pm, Dave Peterson wrote:
Does this mean that you want to change the worksheet that has a codename of
Sheet1 or do you want to change the leftmost worksheet in the workbook?

If it's the leftmost worksheet, you can use:
worksheets(1).Range("B10").formula = "=IF(E5=0,0,E5/C10/C13)"

If it's the codename, you could use:

Option Explicit
Sub changeFormulas()
* * Dim WB As Workbook
* * Dim fs As FileSearch
* * Dim i As Long
* * Dim Wks As Worksheet
* * Dim fName As String

* * Application.DisplayAlerts = False
* * Application.ScreenUpdating = False

* * Set fs = Application.FileSearch

* * With fs
* * * * ' change this to the folder you want
* * * * .LookIn = "C:\Documents and Settings\JLClyde\Desktop\Steve"
* * * * .LookIn = "C:\my documents\excel\test"
* * * * .Filename = "*.xls"
* * * * ' checks to see if there are excel files in the folder specified
* * * * If .Execute 0 Then
* * * * * * For i = 1 To .FoundFiles.Count ' for each file found
* * * * * * * * fName = .FoundFiles(i) 'sets workbook *name to be opened
* * * * * * * * Set WB = Workbooks.Open(fName) 'opens the file
* * * * * * * * With WB
* * * * * * * * * * Set Wks = Nothing
* * * * * * * * * * For Each Wks In WB.Worksheets
* * * * * * * * * * * * If LCase(Wks.CodeName) = LCase("sheet1") Then
* * * * * * * * * * * * * * Exit For
* * * * * * * * * * * * End If
* * * * * * * * * * Next Wks

* * * * * * * * * * If Wks Is Nothing Then
* * * * * * * * * * * * MsgBox "no sheet with a codename Sheet1 in: " _
* * * * * * * * * * * * * * * * * *& vbLf & WB.FullName
* * * * * * * * * * Else
* * * * * * * * * * * * Wks.Range("B10").Formula = "=IF(E5=0,0,E5/C10/C13)"
* * * * * * * * * * End If

* * * * * * * * * * .Close savechanges:=Not (Wks Is Nothing)
* * * * * * * * End With
* * * * * * Next
* * * * End If
* * End With

* * Application.ScreenUpdating = True
* * Application.DisplayAlerts = True
End Sub





jlclyde wrote:

Here is the macro that I have and have used to change a test folder
with test workbooks. *Not all of the sheets have the same same but
they are all sheet1. *Can you help me amend this to have it go to
sheet1 of each workbook?


Thanks,
Jay


Sub changeFormulas()
* * Dim WB As Workbook
* * Dim fs
* * Dim i As Integer


* * Application.DisplayAlerts = False
* * Application.ScreenUpdating = False


* * Set fs = Application.FileSearch


* * With fs
* * * * .LookIn = "C:\Documents and Settings\JLClyde\Desktop\Steve" '
change this to the folder you want
* * * * .Filename = "*.xls"
* * * * If .Execute 0 Then ' checks to see if there are excel files
in the folder specified
* * * * * * For i = 1 To .FoundFiles.Count ' for each file found
* * * * * * * * fname = .FoundFiles(i) 'sets workbook *name to be
opened
* * * * * * * * Set WB = Workbooks.Open(fname) 'opens the file
* * * * * * * * With WB
* * * * * * * * * * Sheet1.Range("B10") = "=IF(E5=0,0,E5/C10/C13)"
* * * * * * * * * * .Close SaveChanges:=True
* * * * * * * * End With
* * * * * * Next
* * * * End If
* * End With


* * Application.ScreenUpdating = True
* * Application.DisplayAlerts = True
End Sub


--

Dave Peterson- Hide quoted text -

- Show quoted text -


Dave,
It is the one that is the left most positoin. I was going around
with worksheets, sheet, sheets. Thank you very much this will do the
trick nicely.
Jay
  #4   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 35,218
Default Change Formula on Multiple Workbooks

Oops. I had a typo:

.worksheets(1).Range("B10").formula = "=IF(E5=0,0,E5/C10/C13)"

That leading dot is very important. Maybe not so in this case. Without the
dot, the worksheets(1) reference will refer to the activeworkbook. But since WB
was just opened, it should be active.

I'd still add that leading dot.

jlclyde wrote:

On Mar 24, 4:18 pm, Dave Peterson wrote:
Does this mean that you want to change the worksheet that has a codename of
Sheet1 or do you want to change the leftmost worksheet in the workbook?

If it's the leftmost worksheet, you can use:
worksheets(1).Range("B10").formula = "=IF(E5=0,0,E5/C10/C13)"

If it's the codename, you could use:

Option Explicit
Sub changeFormulas()
Dim WB As Workbook
Dim fs As FileSearch
Dim i As Long
Dim Wks As Worksheet
Dim fName As String

Application.DisplayAlerts = False
Application.ScreenUpdating = False

Set fs = Application.FileSearch

With fs
' change this to the folder you want
.LookIn = "C:\Documents and Settings\JLClyde\Desktop\Steve"
.LookIn = "C:\my documents\excel\test"
.Filename = "*.xls"
' checks to see if there are excel files in the folder specified
If .Execute 0 Then
For i = 1 To .FoundFiles.Count ' for each file found
fName = .FoundFiles(i) 'sets workbook name to be opened
Set WB = Workbooks.Open(fName) 'opens the file
With WB
Set Wks = Nothing
For Each Wks In WB.Worksheets
If LCase(Wks.CodeName) = LCase("sheet1") Then
Exit For
End If
Next Wks

If Wks Is Nothing Then
MsgBox "no sheet with a codename Sheet1 in: " _
& vbLf & WB.FullName
Else
Wks.Range("B10").Formula = "=IF(E5=0,0,E5/C10/C13)"
End If

.Close savechanges:=Not (Wks Is Nothing)
End With
Next
End If
End With

Application.ScreenUpdating = True
Application.DisplayAlerts = True
End Sub





jlclyde wrote:

Here is the macro that I have and have used to change a test folder
with test workbooks. Not all of the sheets have the same same but
they are all sheet1. Can you help me amend this to have it go to
sheet1 of each workbook?


Thanks,
Jay


Sub changeFormulas()
Dim WB As Workbook
Dim fs
Dim i As Integer


Application.DisplayAlerts = False
Application.ScreenUpdating = False


Set fs = Application.FileSearch


With fs
.LookIn = "C:\Documents and Settings\JLClyde\Desktop\Steve" '
change this to the folder you want
.Filename = "*.xls"
If .Execute 0 Then ' checks to see if there are excel files
in the folder specified
For i = 1 To .FoundFiles.Count ' for each file found
fname = .FoundFiles(i) 'sets workbook name to be
opened
Set WB = Workbooks.Open(fname) 'opens the file
With WB
Sheet1.Range("B10") = "=IF(E5=0,0,E5/C10/C13)"
.Close SaveChanges:=True
End With
Next
End If
End With


Application.ScreenUpdating = True
Application.DisplayAlerts = True
End Sub


--

Dave Peterson- Hide quoted text -

- Show quoted text -


Dave,
It is the one that is the left most positoin. I was going around
with worksheets, sheet, sheets. Thank you very much this will do the
trick nicely.
Jay


--

Dave Peterson
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
Updating Workbooks from multiple links Workbooks TimJames Excel Worksheet Functions 1 December 15th 07 03:34 PM
port formula changes to multiple workbooks? George[_3_] Excel Discussion (Misc queries) 0 July 20th 07 03:43 AM
How do I change cell information in multiple workbooks Truemouse2003 Excel Discussion (Misc queries) 1 April 5th 06 03:10 PM
copy a formula into multiple worksheets and change 1 row down each Will Excel Discussion (Misc queries) 0 February 9th 06 08:27 PM
One formula on multiple workbooks question Josh M Excel Discussion (Misc queries) 1 May 24th 05 03:17 AM


All times are GMT +1. The time now is 08:40 AM.

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

About Us

"It's about Microsoft Excel"