You are here:

Excel/Formula to get replaced by value

Advertisement


Question
QUESTION: In my Excel workbook, 14 columns are there C to P with range C1:P200 Row 1 contains time value. Example: C1=9/27/2014 8:42:34 AM; D1=9/27/2014 9:12:25 AM & so on...till P1.

Output required: C2:C200 should become FORMULA FREE IMMEDIATELY & leave the value when system's time>=C1 Similarly, D2:200 should become FORMULA FREE & leave the value when system's time>=D1 & so on till column P i.e. P2:P200 should become FORMULA FREE & leave the value when system's time>=P1
The code would be pasted in a ws with tab named 'F24' of my Excel workbook. There are 2 more ws in the Excel workbook with tab named 'A4' & '7'. 'A4' contains code as Worksheet event code & '7' updates using real time feeds. Note: The new code in 'F24' should not affect working of either of 'A4' or '7'

ANSWER: In range C1:P200, converting any formula result that is older than now to a value is easy enough:

Sub ConvertOldFormulasToValues()
   Dim oCell as Range
   Application.ScreenUpdating = False
   Application.Calculation = xlCalculationManual
   For Each oCell in Worksheets("TheSheet").Range(C2:P200)
       If oCell.Value < Date + Time Then
         oCell.Value = oCell.Value
       End If
   Next
   Application.ScreenUpdating = True
   Application.Calculation = xlCalculationAutomatic
End Sub

---------- FOLLOW-UP ----------

QUESTION: Sir,
When I run the code, it gives: "Compile error: Syntax error".  I renamed a worksheet as 'TheSheet' & pasted the code as Worksheet event code.  Is it ok or some changes needs to be done?

Answer
I'm sorry, I forgot a couple of quote marks:

Sub ConvertOldFormulasToValues()
   Dim oCell as Range
   Application.ScreenUpdating = False
   Application.Calculation = xlCalculationManual
   For Each oCell in Worksheets("TheSheet").Range("C2:P200")
       If oCell.Value < Date + Time Then
         oCell.Value = oCell.Value
       End If
   Next
   Application.ScreenUpdating = True
   Application.Calculation = xlCalculationAutomatic
End Sub
About Excel
This topic answers questions related to Microsoft Excel spreadsheet (or workbook) stand-alone or Mircrosoft Office Excel including Excel 2003, Excel 2007, Office 2000, and Office XP. You can get Excel help on Excel formulas(or functions), Excell macros, charting in Excel, advanced features, and the general use of Excel. This does not provide a general Excel tutorial nor the basics of using a spreadsheet. It provides specific answers to using Microsoft Excel only. If you do not see your Excel question answered in this area then please ask an Excel question here

Excel

All Answers


Answers by Expert:


Ask Experts

Volunteer


Jan Karel Pieterse

Expertise

Excel and Excel/VBA questions

Experience

Excel MVP

Organizations
Self employed Excel developer

Education/Credentials
Bachelor in Chemical Engineering

Awards and Honors
Microsoft MVP award since 2002

Past/Present Clients
Shell, Fortis bank, ABN-AMRO bank, Morgan Stanley, ...

©2016 About.com. All rights reserved.