+ Reply to Thread
Results 1 to 4 of 4

VBA - Change formula to value if a certain Condition is met

  1. #1
    Registered User
    Join Date
    03-27-2013
    Location
    Wiltshire, England
    MS-Off Ver
    MS 365
    Posts
    81

    VBA - Change formula to value if a certain Condition is met

    I have a range of cells from A1 down to about Z1000, but the range does vary.
    The cells contain data pulled in from various spreadsheets by data link.

    What I need is vba to assess the range and if a cell contains "SM Input" in the formula path then the cell stays as a formula.
    Any cell that does not contain "SM Input" then it converts the formula in that cell to a value.

    My finished range is then either a cell value or a cell formula which contain "SM Input" somewhere in the link path.

    Does a VBA routine exist that will achieve this ?

    Many thanks for any help you can give.

  2. #2
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS 365 Family 64-bit 2411
    Posts
    26,673

    Re: VBA - Change formula to value if a certain Condition is met

    This is not especially hard but I am not clear on what you mean by "formula path". What exactly does the formula look like?

    Here is the idea but unable to perform a reliable test without your file. Also, to confirm, you want to check cells in all 26 columns?

    EDIT: The parameters were reversed in my InStr call. See red for correction

    Please Login or Register  to view this content.
    Last edited by 6StringJazzer; 03-09-2025 at 11:22 AM.
    Jeff
    | | |會 |會 |會 |會 | |:| | |會 |會
    Read the rules
    Use code tags to [code]enclose your code![/code]

  3. #3
    Forum Expert bebo021999's Avatar
    Join Date
    07-22-2011
    Location
    Vietnam
    MS-Off Ver
    Excel 2016
    Posts
    9,641

    Re: VBA - Change formula to value if a certain Condition is met

    Try this:
    PHP Code: 
    Sub test()
    Dim ce As Range
    For Each ce In ActiveSheet.UsedRange
        
    If InStr(1ce.Formula"SM Input") = 0 Then
            ce
    .Value ce.Value
        End 
    If
    Next
    End Sub 
    Quang PT

  4. #4
    Registered User
    Join Date
    03-27-2013
    Location
    Wiltshire, England
    MS-Off Ver
    MS 365
    Posts
    81

    Re: VBA - Change formula to value if a certain Condition is met

    Thanks, your code worked.

    Much appreciated.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. cell change color with formula and condition
    By jack3wong4 in forum Excel General
    Replies: 2
    Last Post: 09-05-2015, 05:56 AM
  2. Change formula if a condition met
    By tsakta13ole in forum Excel General
    Replies: 1
    Last Post: 07-03-2015, 07:04 AM
  3. [SOLVED] Need to change a Sumproduct Formula to incorporate a condition
    By john dalton in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 03-03-2014, 08:35 AM
  4. [SOLVED] Change cell formula (C4) when a if condition is met
    By Rocky2013 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 10-22-2013, 03:52 AM
  5. How to change the formula by its calculated value if condition is true ?
    By Jeferson11 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 02-14-2013, 07:30 PM
  6. Replies: 3
    Last Post: 10-28-2011, 04:47 AM
  7. auto change cell formula on condition of worksheet change in other cells
    By futurejock in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 06-01-2009, 12:11 AM

Tags for this Thread

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