+ Reply to Thread
Results 1 to 4 of 4

Change data based on date field

Hybrid View

  1. #1
    Registered User
    Join Date
    08-19-2009
    Location
    Chicago
    MS-Off Ver
    Excel 2003
    Posts
    16

    Question Change data based on date field

    I have a file, a portion is attached, where I want to paste the value of the formula (in this case, just that of the external data) once it has grabbed the data from an external source.

    If the first time I open the file is Jan 15, I want it to grab the data in columns C, E and G from Jan 1 to Jan 14 and paste each cell's value in the same cell. Any data on Jan 15 or past Jan 15, I don't want the value (hasn't been collected yet).

    If I open the file again on Jan 18, I need the data from Jan 15 to Jan 17.

    I have this macro which works well for grabbing the data and pasting the value, but I am struggling doing this based on the date.

    Dim WS As Worksheet
    Dim Rng1 As Range
    Dim Cell As Range
    Dim lrow As Long
    
    lrow = Cells(Rows.Count, 1).End(xlDown).Row
    
    On Error Resume Next
    
    For Each WS In ActiveWorkbook.Worksheets
        With WS
            On Error Resume Next
            Set Rng1 = Cells.SpecialCells(xlCellTypeFormulas)
            On Error GoTo 0
                If Not Rng1 Is Nothing Then
                    For Each Cell In Rng1
                    If Left(Cell.Formula, 3) = "=AT" Then 'replaces only the externally retrieved data with the value
                        Cell.Value = Cell.Value
                    End If
                    Next
                End If
        Set Rng1 = Nothing
    End With
    
    Next
    Any suggestions on limiting this by date in the first column?
    Last edited by mtbe; 08-27-2009 at 09:51 AM. Reason: Solved

  2. #2
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: Change data based on date field

    I have a file, a portion is attached...
    No attachment. Are the dates stored in a header row of some sort ?

  3. #3
    Registered User
    Join Date
    08-19-2009
    Location
    Chicago
    MS-Off Ver
    Excel 2003
    Posts
    16

    Re: Change data based on date field

    Oops....attached now:
    Attached Files Attached Files

  4. #4
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: Change data based on date field

    Given you have external links obviously this is hard to validate but I think you're saying you want to leave the formulae in place for future dates, correct ?

    Based on your existing code, perhaps then:

    For Each WS In ActiveWorkbook.Worksheets
        With WS
            On Error Resume Next
            Set Rng1 = .Cells.SpecialCells(xlCellTypeFormulas)
            On Error GoTo 0
            If Not Rng1 Is Nothing Then
                For Each Cell In Rng1
                    If Left(Cell.Formula, 3) = "=AT" And Cell.Offset(,1 - Cell.Column) <= Now Then
                        Cell.Value = Cell.Value
                    End If
                Next
            End If
            Set Rng1 = Nothing
        End With
    Next
    the above assumes date value is always in 1st column of sheet - if this is not the case then obviously things get a little more complicated and we'd need more info.

+ 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