+ Reply to Thread
Results 1 to 7 of 7

Convert IF formulas to their values

  1. #1
    GregR
    Guest

    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. #2
    Norman Jones
    Guest

    Re: 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" <[email protected]> wrote in message
    news:[email protected]...
    >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. #3
    GregR
    Guest

    Re: 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" <[email protected]> wrote in message
    > news:[email protected]...
    > >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. #4
    Norman Jones
    Guest

    Re: 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. #5
    GregR
    Guest

    Re: 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. #6
    Norman Jones
    Guest

    Re: 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. #7
    GregR
    Guest

    Re: 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 to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1