Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 246
Default Convert IF formulas to their values

I have a worksheet with various formulas. I want to convert only the
"IF" formulas to their values. Is it possible and if so how? TIA

Greg

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,302
Default Convert IF formulas to their values

Hi Greg,

Try:

'=============
Public Sub Tester()
Dim SH As Worksheet
Dim rng As Range
Dim rCell As Range

Set SH = ActiveSheet
On Error Resume Next
Set rng = Sh.Cells.SpecialCells(xlCellTypeFormulas, 23)
On Error GoTo 0

If Not rng Is Nothing Then
For Each rCell In rng.Cells
With rCell
.Select
If Left(.Formula, 3) = "=IF" Then
.Value = .Value
End If
End With
Next rCell
End If
End Sub
'<<=============


---
Regards,
Norman



"GregR" wrote in message
ups.com...
I have a worksheet with various formulas. I want to convert only the
"IF" formulas to their values. Is it possible and if so how? TIA

Greg



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 246
Default Convert IF formulas to their values

Norman, worked like a champ. Thank you

Greg
Norman Jones wrote:
Hi Greg,

Try:

'=============
Public Sub Tester()
Dim SH As Worksheet
Dim rng As Range
Dim rCell As Range

Set SH = ActiveSheet
On Error Resume Next
Set rng = Sh.Cells.SpecialCells(xlCellTypeFormulas, 23)
On Error GoTo 0

If Not rng Is Nothing Then
For Each rCell In rng.Cells
With rCell
.Select
If Left(.Formula, 3) = "=IF" Then
.Value = .Value
End If
End With
Next rCell
End If
End Sub
'<<=============


---
Regards,
Norman



"GregR" wrote in message
ups.com...
I have a worksheet with various formulas. I want to convert only the
"IF" formulas to their values. Is it possible and if so how? TIA

Greg


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,302
Default Convert IF formulas to their values

Hii Greg,

Please delete:

.Select


This line was only included for testing purposes!

However, try the following version which is more robust and which caters for
multiple forms of IF formula:

'=============
Public Sub Tester2()
Dim Sh As Worksheet
Dim rng As Range
Dim rCell As Range

Set Sh = ActiveSheet
On Error Resume Next
Set rng = Sh.Cells.SpecialCells(xlCellTypeFormulas, 23)
On Error GoTo 0

If Not rng Is Nothing Then
For Each rCell In rng.Cells
With rCell
If .Formula Like "*IF*" Then
.Value = .Value
End If
End With
Next rCell
End If
End Sub
'<<=============


---
Regards,
Norman


  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 246
Default Convert IF formulas to their values

Norman, just one question, what is the 23 in the celltypeformulas and
are there other numbers that have a meaning. TIA

Greg
Norman Jones wrote:
Hii Greg,

Please delete:

.Select


This line was only included for testing purposes!

However, try the following version which is more robust and which caters for
multiple forms of IF formula:

'=============
Public Sub Tester2()
Dim Sh As Worksheet
Dim rng As Range
Dim rCell As Range

Set Sh = ActiveSheet
On Error Resume Next
Set rng = Sh.Cells.SpecialCells(xlCellTypeFormulas, 23)
On Error GoTo 0

If Not rng Is Nothing Then
For Each rCell In rng.Cells
With rCell
If .Formula Like "*IF*" Then
.Value = .Value
End If
End With
Next rCell
End If
End Sub
'<<=============


---
Regards,
Norman




  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,302
Default Convert IF formulas to their values

Hi Greg,

Norman, just one question, what is the 23 in the celltypeformulas and
are there other numbers that have a meaning. TIA


Each of the SpecialCells method constants have numeric values. These
constants can be summed to include multiple options. The value 23 is the
result of adding all of the xlCellTypeFormulas contants and is equvalent, in
Excel, to checking all of the formula options.

---
Regards,
Norman


  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 246
Default Convert IF formulas to their values

Norman, thanks...................the lessons just keep coming

Greg
Norman Jones wrote:
Hi Greg,

Norman, just one question, what is the 23 in the celltypeformulas and
are there other numbers that have a meaning. TIA


Each of the SpecialCells method constants have numeric values. These
constants can be summed to include multiple options. The value 23 is the
result of adding all of the xlCellTypeFormulas contants and is equvalent, in
Excel, to checking all of the formula options.

---
Regards,
Norman


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
convert formulas to values MatthewFlinchem Excel Worksheet Functions 3 May 17th 06 04:39 PM
Convert Values to formulas TSter Excel Worksheet Functions 4 January 15th 06 09:26 PM
Convert formulas to values on save Steve B Excel Programming 5 December 12th 05 09:21 PM
Convert Formulas to Values and Preserve Formatting Tenacity Excel Discussion (Misc queries) 2 August 12th 05 01:00 AM
Select range -- convert formulas to values Johnny[_9_] Excel Programming 3 June 21st 05 03:40 PM


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