+ Reply to Thread
Results 1 to 3 of 3

Formulas into values based on cell

Hybrid View

  1. #1
    Registered User
    Join Date
    11-23-2010
    Location
    Quebec, Canada
    MS-Off Ver
    Excel 2003
    Posts
    9

    Formulas into values based on cell

    Hi, I am trying to convert a set of formulas into values based on a 'date' value in cell A2 i.e. when A2='November 30, 2010' then all formulas in range A4:G22 become values. Is this possible? Also, FYI,
    - The sheet/formulas are protected
    - I am using Excel 2007
    - The spreadsheet is macro-enabled completely

    Any help would be appreciated!

    UPDATE: Hi, thank you very much for the code!! although there was one small change: I would like to convert the range to values based on a specific text entry i.e. when A2='Actuals' then cells become values. Can you clarify on how to change the code for this?

    Thanks,

    Reayn.
    Last edited by Reayn; 11-30-2010 at 05:22 PM.

  2. #2
    Forum Expert Bob Phillips's Avatar
    Join Date
    09-03-2005
    Location
    Wessex
    MS-Off Ver
    Office 2003, 2010, 2013, 2016, 365
    Posts
    3,284

    Re: Formulas into values based on cell

    Something along the lines of

    With Worksheets("Sheet1")
    
        Select Case .Range("A2").Value
    
            Case DateSerial(2010, 11, 30):  .Range("A4:G22").Value = .Range("A4:G22").Value
                    
            Case DateSerial(2010, 12, 12):  .Range("M2:N5").Value = .Range("M2:N5").Value
            
            'etc.
        End Select
    End With

  3. #3
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259

    Re: Formulas into values based on cell

    Hello Reayn,

    Welcome to the Forum!

    If you want the cells to change whenever cell "A2" contains a date, not just today's date, then this macro will do that. You will need to change the password in the macro below from "password" to yours.
    Private Sub Worksheet_Change(ByVal Target As Range)
    
      Dim pwd As String
      Dim Rng As Range
      
        If Target.Cells.Count > 1 Or Intersect(Target, Range("A2")) Is Nothing Then Exit Sub
        
        If Not IsDate(Target) Then Exit Sub
        
        pwd = "password"
        Set Rng = Range("A4:G22")
        
        Application.Calculation = xlCalculationManual
        Application.EnableEvents = False
    
          ActiveSheet.Unprotect pwd
            Rng.Value = Rng.Value
          ActiveSheet.Protect pwd
          
        Application.Calculation = xlCalculationAutomatic
        Application.EnableEvents = True
    
    End Sub

    How to Save a Worksheet Event Macro
    1. Copy the macro using CTRL+C keys.
    2. Open your Workbook and Right Click on the Worksheet's Name Tab for the Worksheet the macro will run on.
    3. Left Click on View Code in the pop up menu.
    4. Paste the macro code using CTRL+V
    5. Make any custom changes to the macro if needed at this time.
    6. Save the macro in your Workbook using CTRL+S
    Sincerely,
    Leith Ross

    Remember To Do the Following....

    1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.
    2. Thank those who have helped you by clicking the Star below the post.
    3. Please mark your post [SOLVED] if it has been answered satisfactorily.


    Old Scottish Proverb...
    Luathaid gu deanamh maille! (Rushing causes delays!)

+ 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