+ Reply to Thread
Results 1 to 10 of 10

Replace vlookups with values after a certain date.

  1. #1
    Registered User
    Join Date
    10-14-2013
    Location
    uk
    MS-Off Ver
    2016
    Posts
    87

    Replace vlookups with values after a certain date.

    Hi Folks
    I need an auto run macro that will replace a range of vlookup formulas with their cell values, however the range should be from yesterday's date.
    The first column provides the date.
    So when I open first time in the morning the macro will run and replace all yesterdays vlookups with their values.

    I have the macro below.

    Sub Formulatodata()
    'updatedbyJim
    Dim Rng As Range
    Dim WorkRng As Range
    On Error Resume Next
    xTitleId = "replace formulas with values"
    Set WorkRng = Application.Selection
    Set WorkRng = Application.InputBox("Range", xTitleId, WorkRng.Address, Type:=8)
    Application.ScreenUpdating = False
    For Each Rng In WorkRng
    Rng.Value = Rng.Text
    Next
    Application.ScreenUpdating = True
    End Sub

    This allows me to manually select the range, however I need help with the date part .
    sample attached
    Attached Files Attached Files

  2. #2
    Registered User
    Join Date
    10-14-2013
    Location
    uk
    MS-Off Ver
    2016
    Posts
    87

    Re: Replace vlookups with values after a certain date.

    any ideas folks ?

  3. #3
    Forum Expert skywriter's Avatar
    Join Date
    06-09-2014
    Location
    USA
    MS-Off Ver
    2016
    Posts
    2,760

    Re: Replace vlookups with values after a certain date.

    will replace a range of vlookup formulas with their cell values
    Which vlookup formulas?

    The first column provides the date.
    When I click on a cell in column A and choose trace dependents it shows nothing. Indicating that no formulas are dependent on those cells.

    however I need help with the date part
    This doesn't make sense to me because of the other two things that don't make sense to me.
    Click the * Add Reputation button in the lower left hand corner of this post to say thanks.

    Don't forget to mark this thread SOLVED by going to the "Thread Tools" drop down list above your first post and choosing solved.

  4. #4
    Registered User
    Join Date
    10-14-2013
    Location
    uk
    MS-Off Ver
    2016
    Posts
    87

    Re: Replace vlookups with values after a certain date.

    Hi Skywriter, thanks for the reply
    The row of vlookups dated yesterday are what needs replacing.
    so for instance if I open the spreadsheet on the 2nd I need all the vlookups on the 1st replaced with their values.
    so the range in that instance would be A1:G64.
    Then when I open it on the 3rd I need all the vlookups on the 2nd replaced with their values
    so the range in this instance would be A65:G66
    and so on.

  5. #5
    Forum Expert skywriter's Avatar
    Join Date
    06-09-2014
    Location
    USA
    MS-Off Ver
    2016
    Posts
    2,760

    Re: Replace vlookups with values after a certain date.

    Your first three rows don't have vlookups, I'll assume that was just a typo. So what you want is for code that looks at the cells in column A and if they were the day before today then copy the vlookup results in that row and paste the values on top of the formula thereby replacing the formula with whatever the value was?
    The reason I ask is your vlookups reference a file path so we have no way of knowing if these formulas change values as the dates change, which would mean we would have to, through code, manipulate the formula to have the value it did the previous day before turning the results into just a value in the cell.

    I'll assume you want to just look in column A and whatever the formula results are for today those are what you want.

    Please Login or Register  to view this content.
    Last edited by skywriter; 06-20-2015 at 02:37 PM.

  6. #6
    Registered User
    Join Date
    10-14-2013
    Location
    uk
    MS-Off Ver
    2016
    Posts
    87

    Re: Replace vlookups with values after a certain date.

    Hi thanks Sykwriter
    correct it was a typo A4 was the starting reference. You are correct in your assumption once the values are entered they do not change.
    The vlookups are not changed, though we do maintain a separate sheet for each month which looks up its monthly equivalent so Receipts May looks up Front door May, and Receipts June looks up Front door June and so on.
    I ran the code and get a run-time mismatch error 13 debug indicates this line "cellDate = .Cells(c, 1).Value"

  7. #7
    Forum Expert skywriter's Avatar
    Join Date
    06-09-2014
    Location
    USA
    MS-Off Ver
    2016
    Posts
    2,760

    Re: Replace vlookups with values after a certain date.

    I ran the code and get a run-time mismatch error 13 debug indicates this line "cellDate = .Cells(c, 1).Value"
    Yeah I get that error too and it's because in A57 & A58 you have a #N/A. You need to fix the cell or we will have to account for that in the code. Since it was a sample and you have links to files that only you have I figured it was only going to be in the sample not in your actual spreadsheet.
    Last edited by skywriter; 06-21-2015 at 12:31 PM.

  8. #8
    Registered User
    Join Date
    10-14-2013
    Location
    uk
    MS-Off Ver
    2016
    Posts
    87

    Re: Replace vlookups with values after a certain date.

    I deleted them and ran the code but the vlookups remain ?
    In the original sheets there is N/A in all the cells that are currently unpopulated with data.
    The sheet runs to around 1000 rows.
    so if there has been say 50 deliveries the remaining 950 rows and columns have n/a in them.

  9. #9
    Forum Expert skywriter's Avatar
    Join Date
    06-09-2014
    Location
    USA
    MS-Off Ver
    2016
    Posts
    2,760

    Re: Replace vlookups with values after a certain date.

    I ran this code on the sample sheet you provided. I typed in June 20, 2015 into a couple of the cells in the A column and ran the code.
    The VLookups in the columns to the right of the A cells that I typed the date into were replaced with their values. The #N/A cells were ignored.

    Please Login or Register  to view this content.

  10. #10
    Registered User
    Join Date
    10-14-2013
    Location
    uk
    MS-Off Ver
    2016
    Posts
    87

    Re: Replace vlookups with values after a certain date.

    Yep that works great, can we get it to change all the vlookups previous to the 20th
    and to auto run at start up ?

+ 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. Vlookups that return multiple values
    By capitalsfan in forum Excel Formulas & Functions
    Replies: 6
    Last Post: 12-18-2013, 12:11 PM
  2. Vlookups with multiple values for same ID
    By Daniel1986 in forum Excel General
    Replies: 9
    Last Post: 06-22-2012, 03:36 PM
  3. Using VLOOKUPS to return mulitple values
    By mscomputertutor in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 08-14-2010, 10:05 AM
  4. Replace Fixed Reference in 0000's of VLOOKUPs
    By 2709236 in forum Excel General
    Replies: 2
    Last Post: 11-23-2009, 04:03 PM
  5. Vlookups to return format as well as values
    By kosciosco in forum Excel General
    Replies: 1
    Last Post: 11-21-2007, 09:49 AM

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