+ Reply to Thread
Results 1 to 8 of 8

Help request to change formula to value

Hybrid View

mso3 Help request to change... 07-19-2015, 09:35 PM
jordan2322 Re: Help request to change... 07-19-2015, 10:19 PM
mso3 Re: Help request to change... 07-19-2015, 10:55 PM
alansidman Re: Help request to change... 07-19-2015, 11:13 PM
mikerickson Re: Help request to change... 07-19-2015, 11:50 PM
mso3 Re: Help request to change... 07-19-2015, 11:20 PM
jordan2322 Re: Help request to change... 07-19-2015, 11:47 PM
mso3 Re: Help request to change... 07-20-2015, 12:59 AM
  1. #1
    Forum Contributor
    Join Date
    06-29-2014
    Location
    India
    MS-Off Ver
    2010 Windows 10 64 bits
    Posts
    1,269

    Help request to change formula to value

    Hi friends,
    The code is working fine but I have following problems in it.
    1. The code is running after clicking on any cells on the personal sheet.
    2. The formula is not changing to value.
    I want the value instead of formula.

    Any help will be highly appreciated.

    Thanking you in anticipation.
    Attached Files Attached Files
    Sincerely,

    mso3

  2. #2
    Forum Contributor
    Join Date
    11-16-2011
    Location
    Australia
    MS-Off Ver
    Excel 2010
    Posts
    405

    Re: Help request to change formula to value

    In point 1. you mention the code is "running after clicking on any of the cells".. your code is placed inside the Worksheet_Change event routine, is this not where you want it?

    If not please clarify where you want it - OR - describe the operations that must occur in order for it to run.

    Also, I would consider NOT using a mixture of VBA as well as worksheet functions.. it would be easier to manage if it were completely done in VBA.

    Regards
    Jordan

  3. #3
    Forum Contributor
    Join Date
    06-29-2014
    Location
    India
    MS-Off Ver
    2010 Windows 10 64 bits
    Posts
    1,269

    Re: Help request to change formula to value

    Hi,

    I want to place the code in Worksheet_Change event to perform the action after entering the date in column 'P and AD' respectively only and not entring any data on the sheet in any cell.

    Please suggest me an amendment to achieve the target automatically after entering the dates.

    Thank you.

  4. #4
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 insider Version 2505 Win 11
    Posts
    24,755

    Re: Help request to change formula to value

    I use the following to change formulas to hard coded data. You could incorporate this into your code

    Sub copypastespecial()
        ActiveCell.Copy
        ActiveCell.PasteSpecial xlPasteValues
        Application.CutCopyMode = False
        
    End Sub
    Alan עַם יִשְׂרָאֵל חַי


    Change an Ugly Report with Power Query
    Database Normalization
    Complete Guide to Power Query
    Man's Mind Stretched to New Dimensions Never Returns to Its Original Form

  5. #5
    Forum Expert mikerickson's Avatar
    Join Date
    03-30-2007
    Location
    Davis CA
    MS-Off Ver
    Excel 2011
    Posts
    6,229

    Re: Help request to change formula to value

    Quote Originally Posted by alansidman View Post
    I use the following to change formulas to hard coded data. You could incorporate this into your code

    Sub copypastespecial()
        ActiveCell.Copy
        ActiveCell.PasteSpecial xlPasteValues
        Application.CutCopyMode = False
        
    End Sub
    I prefer
    ActiveCell.Value = ActiveCell.Value
    since it doesn't fiddle with the clipboard.
    _
    ...How to Cross-post politely...
    ..Wrap code by selecting the code and clicking the # or read this. Thank you.

  6. #6
    Forum Contributor
    Join Date
    06-29-2014
    Location
    India
    MS-Off Ver
    2010 Windows 10 64 bits
    Posts
    1,269

    Re: Help request to change formula to value

    Hi Alan,
    Thank you. Sorry, I don't want to run code from standard module. It's not a question of copy/paste. I want the output after entering the dates in the cell automatically and change to value.

    Please suggest me a correction in the code to achieve the target automatically. I need a sheet module code only.

    Thank you.

  7. #7
    Forum Contributor
    Join Date
    11-16-2011
    Location
    Australia
    MS-Off Ver
    Excel 2010
    Posts
    405

    Re: Help request to change formula to value

    You could encapsulate your worksheet_change code in the following way..

    Private Sub Worksheet_Change(ByVal Target As Range)
        ' 16 = P, 17 = Q, change these columns numbers to what you need
        If Target.Column = 16 Or Target.Column = 17 Then
            ' All your calculation code goes here
        End If
    End Sub
    Let me know if that helps

  8. #8
    Forum Contributor
    Join Date
    06-29-2014
    Location
    India
    MS-Off Ver
    2010 Windows 10 64 bits
    Posts
    1,269

    Re: Help request to change formula to value

    Hi,
    I have made necessary changes but getting error 91.

    Something is wrong in my coding. Sorry for not understanding your suggestion correctly.

    Please do the necessary amendments in the code below to achieve the target.

    Option Explicit
    
    Private Sub Worksheet_Change(ByVal Target As Range)
    
    Dim cell As Range
        ' 16 = P, 30 = AD
        If Target.Column = 16 Or Target.Column = 30 Then
            Application.EnableEvents = False
    If Not Intersect(Target, Range("P:P")) Is Nothing Then
        For Each cell In Intersect(Target, Range("P:P"))
        If Target.Row < 9 Then Exit Sub
        If Target.Column <> 16 Then Exit Sub
            If cell.Value = "" Then
                        Cells(cell.Row, "W").Value = ""
    Else
    Cells(cell.Row, "W").Formula = _
    "=IF(RC[-7]="""","""",IF(RC[-20]=""Duplicate"",""Duplicate"",IF(AND(RC[-7]=""-"",RC[-6]=""-""),""-"",IF(COUNT(RC[-7]:RC[-6])=1,""Sanctioned"",""Expired""))))"
    '.Value = .Value
                        End If
            Columns.AutoFit
        Next cell
    End If
    
    'Remark 3
    
    If Not Intersect(Target, Range("P:P")) Is Nothing Then
        For Each cell In Intersect(Target, Range("P:P"))
        If Target.Row < 9 Then Exit Sub
        If Target.Column <> 16 Then Exit Sub
    If cell.Value = "" Then
                        Cells(cell.Row, "AG").Value = ""
    Else
    Cells(cell.Row, "AG").Formula = _
    "=IF(RC[-10]=""Sanctioned"",""Send mail"",IF(RC[-10]=""Expired"",""Closed"",IF(RC[-10]=""-"",""Closed"",IF(RC[-10]=""Duplicate"",""Closed"",""""))))"
    '.Value = .Value
                        End If
            Columns.AutoFit
        Next cell
    End If
    End If
    
    'Remark2
    
    If Not Intersect(Target, Range("AD:AD")) Is Nothing Then
        For Each cell In Intersect(Target, Range("AD:AD"))
        If Target.Row < 9 Then Exit Sub
        If Target.Column <> 30 Then Exit Sub
    If cell.Value = "" Then
                        Cells(cell.Row, "AF").Value = ""
    Else
    Cells(cell.Row, "AF").Formula = _
    "=IF(RC[-2]="""","""",IF(AND(RC[-2]=""-"",RC[-1]=""-""),""-"",IF(COUNT(RC[-2]:RC[-1])=1,""Send mail"",""Expired"")))"
    '.Value = .Value
                        End If
            Columns.AutoFit
        Next cell
    End If
        Application.EnableEvents = True
    End Sub
    Thank you.

+ 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. Function request to change numbers to word in Hindi
    By mso3 in forum Excel Programming / VBA / Macros
    Replies: 37
    Last Post: 05-31-2020, 05:36 AM
  2. Wait for winhttp request to be done (much like XML http request)
    By JasperD in forum Excel Programming / VBA / Macros
    Replies: 21
    Last Post: 07-23-2015, 09:26 AM
  3. formula request
    By ryan0212 in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 02-15-2015, 10:07 AM
  4. Font Color Change in tabs and sheets
    By m1chaelch0 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 12-17-2012, 09:48 PM
  5. change request template
    By kadams99 in forum Excel General
    Replies: 2
    Last Post: 09-22-2010, 01:19 PM
  6. Request macro code - when cell change event
    By Rhey1971 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 05-01-2006, 06:55 AM
  7. formula request
    By A. Toczko in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 05-16-2005, 10:06 PM

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