+ Reply to Thread
Results 1 to 8 of 8

Copying cell information based on date

Hybrid View

  1. #1
    Registered User
    Join Date
    08-29-2014
    Location
    Virginia
    MS-Off Ver
    2010
    Posts
    6

    Copying cell information based on date

    Good Morning,

    I'm trying to get certain cells to populate information from another cell based on a date. I.E. - I want O4:Z4 to copy what is in cell D8 (an amount) when O2:Z2 are Date(Now) or greater. I need to show when something in D8 is actually 0 and also if/and when the next date occurs and D8 changes that it doesn't change the information in the previous O4:Z4 cell. My code is listed below and the document is attached for a better understanding of it all.

    Can anyone help?!?!? PLEASE!

    Private Sub Worksheet_Calculate()
    
    
    On Error Resume Next
    If DateValue(Range("F4:F5")) = "" Then Exit Sub
    
    On Error GoTo WorkSheet_Calculate_ErrorHandler
    
    If Range("O4").Value = "0" Then
    
        If DateValue(Now) >= DateValue(Range("O2")) Then
          Range("O4").Value = Range("C8").Value
        End If
    
    End If
    
    If Range("P4").Value = "0" Then
    
        If DateValue(Now) >= DateValue(Range("P2")) Then
          Range("P4").Value = Range("C8").Value
        End If
    
    End If
    
    If Range("R4").Value = "0" Then
    
        If DateValue(Now) >= DateValue(Range("R2")) Then
          Range("R4").Value = Range("C8").Value
        End If
    
    End If
    
    If Range("S4").Value = "0" Then
    
        If DateValue(Now) >= DateValue(Range("S2")) Then
          Range("S4").Value = Range("C8").Value
        End If
    
    End If
    
    If Range("T4").Value = "0" Then
    
        If DateValue(Now) >= DateValue(Range("T2")) Then
          Range("T4").Value = Range("C8").Value
        End If
    
    End If
    
    If Range("U4").Value = "0" Then
    
        If DateValue(Now) >= DateValue(Range("U2")) Then
          Range("U4").Value = Range("C8").Value
        End If
    
    End If
    
    If Range("V4").Value = "0" Then
    
        If DateValue(Now) >= DateValue(Range("V2")) Then
          Range("V4").Value = Range("C8").Value
        End If
    
    End If
    
    If Range("W4").Value = "0" Then
    
        If DateValue(Now) >= DateValue(Range("W2")) Then
          Range("W4").Value = Range("C8").Value
        End If
    
    End If
    
    If Range("X4").Value = "0" Then
    
        If DateValue(Now) >= DateValue(Range("X2")) Then
          Range("X4").Value = Range("C8").Value
        End If
    
    End If
    
    If Range("Y4").Value = "0" Then
    
        If DateValue(Now) >= DateValue(Range("Y2")) Then
          Range("Y4").Value = Range("C8").Value
        End If
    
    End If
    
    If Range("Z4").Value = "0" Then
    
        If DateValue(Now) >= DateValue(Range("Z2")) Then
          Range("Z4").Value = Range("C8").Value
        End If
    
    End If
    
    
    
    Exit Sub
    
    WorkSheet_Calculate_ErrorHandler:
    Stop
    
    
    End Sub
    
    Private Sub Worksheet_Change(ByVal Target As Range)
    
    If DateValue(Now) = DateValue(Range("O2").Value) Then
    
        If Range("O4").Value <> Range("C8").Value Then
          Range("O4").Value = Range("C8").Value
        End If
       
    End If
    
    If DateValue(Now) = DateValue(Range("P2").Value) Then
    
        If Range("P4").Value <> Range("C8").Value Then
          Range("P4").Value = Range("C8").Value
        End If
    
    End If
    
    If DateValue(Now) = DateValue(Range("R2").Value) Then
    
        If Range("R4").Value <> Range("C8").Value Then
          Range("R4").Value = Range("C8").Value
        End If
    
    End If
    
    If DateValue(Now) = DateValue(Range("S2").Value) Then
    
        If Range("S4").Value <> Range("C8").Value Then
          Range("S4").Value = Range("C8").Value
        End If
    
    End If
    
    If DateValue(Now) = DateValue(Range("T2").Value) Then
    
        If Range("T4").Value <> Range("C8").Value Then
          Range("T4").Value = Range("C8").Value
        End If
    
    End If
    
    If DateValue(Now) = DateValue(Range("U2").Value) Then
    
        If Range("U4").Value <> Range("C8").Value Then
          Range("U4").Value = Range("C8").Value
        End If
    End If
    
    If DateValue(Now) = DateValue(Range("V2").Value) Then
    
        If Range("V4").Value <> Range("C8").Value Then
          Range("V4").Value = Range("C8").Value
        End If
    End If
    
    If DateValue(Now) = DateValue(Range("W2").Value) Then
    
        If Range("W4").Value <> Range("C8").Value Then
          Range("W4").Value = Range("C8").Value
        End If
    End If
    
    If DateValue(Now) = DateValue(Range("X2").Value) Then
    
        If Range("X4").Value <> Range("C8").Value Then
          Range("X4").Value = Range("C8").Value
        End If
    End If
    
    If DateValue(Now) = DateValue(Range("Y2").Value) Then
    
        If Range("Y4").Value <> Range("C8").Value Then
          Range("Y4").Value = Range("C8").Value
        End If
    End If
    
    If DateValue(Now) = DateValue(Range("Z2").Value) Then
    
        If Range("Z4").Value <> Range("C8").Value Then
          Range("Z4").Value = Range("C8").Value
        End If
    End If
    
    If Not Intersect(Target, Range("F6")) Is Nothing Then
    If Target.Count > 1 Then Exit Sub
    Application.ScreenUpdating = False
    Application.EnableEvents = False
    With Target.Offset(-2, 21)
        .Formula = Range("C8").Value
    End With
    Application.EnableEvents = True
    Application.ScreenUpdating = True
    End If
    
    
    
    If Not Intersect(Target, Range("F7")) Is Nothing Then
    If Target.Count > 1 Then Exit Sub
    Application.ScreenUpdating = False
    Application.EnableEvents = False
    With Target.Offset(-3, 22)
        .Formula = Range("C8").Value
    End With
    Application.EnableEvents = True
    Application.ScreenUpdating = True
    End If
        
    
    
    
    End Sub
    Attached Files Attached Files

  2. #2
    Valued Forum Contributor Naveed Raza's Avatar
    Join Date
    11-04-2012
    Location
    India, Hyderabad
    MS-Off Ver
    Excel, Access 2007/2010
    Posts
    1,338

    Re: Copying cell information based on date

    what exactly u want here ?

    what ever amount is there in C8 cell that amount should copy to all O4:Z4 cells when F8 cell has today's date or future date.

    is it right ?
    Thanks - Naveed
    -----------------------------
    If the suggestion helps you, then Click * to Add Reputation
    To Attach File: Go Advanced>>Manage Attachments>>Add Files (In Top Right Corner)>>SelectFiles>>.........Locate Your File(s)>>Upload Files>>Done (In Bottom Right)
    1. Use [code] code tags [\code]. It keeps posts clean, easy-to-read, and maintains VBA formatting.
    2. If you are happy with a solution to your problem, mark the thread as [SOLVED] using the tools at the top.

  3. #3
    Registered User
    Join Date
    08-29-2014
    Location
    Virginia
    MS-Off Ver
    2010
    Posts
    6

    Re: Copying cell information based on date

    Only problem with that is the $0 amount in O4 has now been updated to $1,000. How do I keep that at $0?

  4. #4
    Valued Forum Contributor Naveed Raza's Avatar
    Join Date
    11-04-2012
    Location
    India, Hyderabad
    MS-Off Ver
    Excel, Access 2007/2010
    Posts
    1,338

    Re: Copying cell information based on date

    I test your code i found some error, just replace your below code with below one

    Your Code
    If DateValue(Range("F4:F5")) = "" Then Exit Sub
    replace with this one
    If Range("F4").Value = "" And Range("F5").Value = "" Then Exit Sub

  5. #5
    Registered User
    Join Date
    08-29-2014
    Location
    Virginia
    MS-Off Ver
    2010
    Posts
    6

    Re: Copying cell information based on date

    Essentially yes. D8 will change throughtout time based on additional information being entered in. In the example that I attached, I did not enter in $1,000 in F14 which updates D8 until 10/22/14. So I wanted 10/21/14 (O2) to be 0 and 10/22/14 (P2) to be $1,000. However, since R2:V2 have already happened I wanted them to also populate what is already in D8 which would be $1,000 and if something was entered in additional amount in F15 which would then take the total of F14 + F15 and calculate that in D8,today's date of 10/27/14 (V2) would be the "new" amount in D8.

  6. #6
    Valued Forum Contributor Naveed Raza's Avatar
    Join Date
    11-04-2012
    Location
    India, Hyderabad
    MS-Off Ver
    Excel, Access 2007/2010
    Posts
    1,338

    Re: Copying cell information based on date

    How we can come to know that 1000 pertains to which date ?

  7. #7
    Registered User
    Join Date
    08-29-2014
    Location
    Virginia
    MS-Off Ver
    2010
    Posts
    6

    Re: Copying cell information based on date

    In the example I gave, 10/21 had already passed and information was entered in on 10/22 which populated that cell. Now I just need it to populate all the cells in between 10/22 and today with $1000 because nothing else has been entered.

    I tried adding your formula to a blank version of the example and it keeps looping and freezes up. Any suggestions?

  8. #8
    Registered User
    Join Date
    08-29-2014
    Location
    Virginia
    MS-Off Ver
    2010
    Posts
    6

    Re: Copying cell information based on date

    Could my problem be having a formula (=Max(G14:G522)) in C8 and trying to run a macro to read C8 depending on certain days?

+ 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. [SOLVED] Copying cell data from one sheet to another based on date.
    By Skeeterj in forum Excel Programming / VBA / Macros
    Replies: 19
    Last Post: 01-07-2014, 04:17 PM
  2. Transfer cell information to another sheet, based on the date
    By twisted31 in forum Excel Formulas & Functions
    Replies: 9
    Last Post: 12-09-2013, 07:05 PM
  3. Replies: 3
    Last Post: 10-31-2013, 04:23 PM
  4. Replies: 1
    Last Post: 09-12-2012, 10:40 AM
  5. Copying information tab to tab based on criteria
    By leem in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 05-27-2010, 01:53 PM

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