Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 349
Default How can I loop through all Formula in a workbook?

I tried Cells.SpecialCells(.... xlCellTypeFormulas...) but no luck.

Anyone have this code snippet?

Thanks,
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,302
Default How can I loop through all Formula in a workbook?

Hi Peter,

I tried Cells.SpecialCells(.... xlCellTypeFormulas...) but no luck.


Anyone have this code snippet?


Your "no luck" is far from explicit, but try something like:

'=============
Public Sub Tester001()
Dim rng As Range
Dim rCell As Range

On Error Resume Next
Set rng = Cells.SpecialCells(xlCellTypeFormulas)
On Error GoTo 0

If Not rng Is Nothing Then
For Each rCell In rng.Cells
'do someting. e.g.:
rCell.Interior.ColorIndex = 6
Next rCell
End If

End Sub
'<<=============


---
Regards,
Norman


"Peter" wrote in message
...
I tried Cells.SpecialCells(.... xlCellTypeFormulas...) but no luck.

Anyone have this code snippet?

Thanks,



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,302
Default How can I loop through all Formula in a workbook?

Hi Peter,

And if you wish to find all formulae in the workbook, try:

'=============
Public Sub Tester002()
Dim WB As Workbook
Dim SH As Worksheet
Dim rng As Range
Dim rCell As Range

Set WB = Workbooks("Book1.xls") '<<==== CHANGE

For Each SH In WB.Worksheets
On Error Resume Next
Set rng = SH.Cells.SpecialCells(xlCellTypeFormulas)
On Error GoTo 0

If Not rng Is Nothing Then
For Each rCell In rng.Cells
'do someting. e.g.:
rCell.Interior.ColorIndex = 6
Next rCell
End If
Next SH

End Sub
'<<=============


---
Regards,
Norman



"Norman Jones" wrote in message
...
Hi Peter,

I tried Cells.SpecialCells(.... xlCellTypeFormulas...) but no luck.


Anyone have this code snippet?


Your "no luck" is far from explicit, but try something like:

'=============
Public Sub Tester001()
Dim rng As Range
Dim rCell As Range

On Error Resume Next
Set rng = Cells.SpecialCells(xlCellTypeFormulas)
On Error GoTo 0

If Not rng Is Nothing Then
For Each rCell In rng.Cells
'do someting. e.g.:
rCell.Interior.ColorIndex = 6
Next rCell
End If

End Sub
'<<=============


---
Regards,
Norman



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default How can I loop through all Formula in a workbook?

I'd add one more line:

Set rng = nothing '<-- added
On Error Resume Next
Set rng = SH.Cells.SpecialCells(xlCellTypeFormulas)
On Error GoTo 0

If there are no formulas on a worksheet, then rng won't change. And depending
on what's going to happen to those cells with formulas, it could be a problem.

And to the OP, Norman showed how to get a range with all the formulas. If
you're doing something like changing the fill color, you can do it all at
once--you don't need to loop through those cells.

Norman Jones wrote:

Hi Peter,

And if you wish to find all formulae in the workbook, try:

'=============
Public Sub Tester002()
Dim WB As Workbook
Dim SH As Worksheet
Dim rng As Range
Dim rCell As Range

Set WB = Workbooks("Book1.xls") '<<==== CHANGE

For Each SH In WB.Worksheets
On Error Resume Next
Set rng = SH.Cells.SpecialCells(xlCellTypeFormulas)
On Error GoTo 0

If Not rng Is Nothing Then
For Each rCell In rng.Cells
'do someting. e.g.:
rCell.Interior.ColorIndex = 6
Next rCell
End If
Next SH

End Sub
'<<=============

---
Regards,
Norman

"Norman Jones" wrote in message
...
Hi Peter,

I tried Cells.SpecialCells(.... xlCellTypeFormulas...) but no luck.


Anyone have this code snippet?


Your "no luck" is far from explicit, but try something like:

'=============
Public Sub Tester001()
Dim rng As Range
Dim rCell As Range

On Error Resume Next
Set rng = Cells.SpecialCells(xlCellTypeFormulas)
On Error GoTo 0

If Not rng Is Nothing Then
For Each rCell In rng.Cells
'do someting. e.g.:
rCell.Interior.ColorIndex = 6
Next rCell
End If

End Sub
'<<=============


---
Regards,
Norman


--

Dave Peterson
  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,302
Default How can I loop through all Formula in a workbook?

Hi Dave,

I'd add one more line:


So would I!

Thank you!


---
Regards,
Norman



"Dave Peterson" wrote in message
...
I'd add one more line:

Set rng = nothing '<-- added
On Error Resume Next
Set rng = SH.Cells.SpecialCells(xlCellTypeFormulas)
On Error GoTo 0

If there are no formulas on a worksheet, then rng won't change. And
depending
on what's going to happen to those cells with formulas, it could be a
problem.

And to the OP, Norman showed how to get a range with all the formulas. If
you're doing something like changing the fill color, you can do it all at
once--you don't need to loop through those cells.





  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default How can I loop through all Formula in a workbook?

This works for me

Dim cell As Range
For Each cell In Cells.SpecialCells(xlCellTypeFormulas)
Debug.Print cell.Address
Next cell


--
HTH

Bob Phillips

(remove nothere from email address if mailing direct)

"Peter" wrote in message
...
I tried Cells.SpecialCells(.... xlCellTypeFormulas...) but no luck.

Anyone have this code snippet?

Thanks,



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
loop through a column on a workbook copying data on each row to another workbook, then copy data back to the original workbook burl_rfc Excel Programming 1 April 1st 06 08:48 PM
copy,paste and loop through workbook TUNGANA KURMA RAJU Excel Discussion (Misc queries) 0 December 6th 05 12:31 PM
Loop through all sheets in workbook jennie Excel Programming 7 October 26th 05 11:54 AM
Workbook Loop Headache Turin[_4_] Excel Programming 1 August 23rd 05 10:42 PM
Code to Loop thru a Workbook Leo Excel Programming 3 May 20th 04 10:08 PM


All times are GMT +1. The time now is 08:26 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"