+ Reply to Thread
Results 1 to 9 of 9

Macro to check if Cell=today() then paste values in cells below

  1. #1
    Registered User
    Join Date
    02-21-2013
    Location
    melbourne, victoria
    MS-Off Ver
    2010
    Posts
    28

    Macro to check if Cell=today() then paste values in cells below

    Hello,

    See attachment for example

    Example.xlsx

    I'm working with reporting on some dynamic data from SQL where todays results are only available today, to handle this i'm using IF in excel to only update the value of the cells in question when the date above them is today's date. The issue this gives me is that while it displays values I want, if I were to add 1 to them, the result would become 1, losing the initial value. A workaround for this is if after I update the value through the IF forumla I copy/paste special values.

    Effectively what I am looking for in a macro would be something along these lines:

    IF value in a column in row 12 = today()
    then select values in same column, rows 13 - 21
    copy
    paste special

    end

    Sorry for basically asking someone to write a macro for me but I've no experience doing it myself and have been trying to steal other code for a few days and just haven't been able to get it to work

    Cheers,

  2. #2
    Forum Expert
    Join Date
    08-12-2012
    Location
    Sydney, Australia
    MS-Off Ver
    Excel 2010
    Posts
    5,636

    Re: Macro to check if Cell=today() then paste values in cells below

    do you need paste special values? or normal copy paste will work?
    Please Login or Register  to view this content.
    normal copy paste

    Please Login or Register  to view this content.
    paste special values
    Attached Files Attached Files
    Last edited by humdingaling; 08-04-2014 at 09:15 PM.
    If you are satisfied with the solution(s) provided, please mark your thread as Solved.
    Select Thread Tools-> Mark thread as Solved. To undo, select Thread Tools-> Mark thread as Unsolved.

  3. #3
    Registered User
    Join Date
    02-21-2013
    Location
    melbourne, victoria
    MS-Off Ver
    2010
    Posts
    28

    Re: Macro to check if Cell=today() then paste values in cells below

    Would have to be paste special values, removing the formula is the key to getting the result to display exactly how it needs to

  4. #4
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 Version 2405 Win 11 Home 64 Bit
    Posts
    23,897

    Re: Macro to check if Cell=today() then paste values in cells below

    Try this code:

    Please Login or Register  to view this content.
    How to install your new code
    1. Copy the Excel VBA code
    2. Select the workbook in which you want to store the Excel VBA code
    3. Press Alt+F11 to open the Visual Basic Editor
    4. Choose Insert > Module
    5. Edit > Paste the macro into the module that appeared
    6. Close the VBEditor
    7. Save your workbook (Excel 2007+ select a macro-enabled file format, like *.xlsm)

    To run the Excel VBA code:
    1. Press Alt-F8 to open the macro list
    2. Select a macro in the list
    3. Click the Run button
    Alan עַם יִשְׂרָאֵל חַי


    Change an Ugly Report with Power Query
    Database Normalization
    Complete Guide to Power Query
    Man's Mind Stretched to New Dimensions Never Returns to Its Original Form

  5. #5
    Forum Expert
    Join Date
    08-12-2012
    Location
    Sydney, Australia
    MS-Off Ver
    Excel 2010
    Posts
    5,636

    Re: Macro to check if Cell=today() then paste values in cells below

    oh i got rid of your formulas...unsure why you would need them if you are going to trigger macro to do it

  6. #6
    Registered User
    Join Date
    02-21-2013
    Location
    melbourne, victoria
    MS-Off Ver
    2010
    Posts
    28

    Re: Macro to check if Cell=today() then paste values in cells below

    Thank you very much both humdingaling and alansidman, works a charm.

    One more question, I already have a VB script to open this report and update it (to get new data from SQL), would I be able to code it to run the macro as well?

    Cheers,

  7. #7
    Forum Expert
    Join Date
    08-12-2012
    Location
    Sydney, Australia
    MS-Off Ver
    Excel 2010
    Posts
    5,636

    Re: Macro to check if Cell=today() then paste values in cells below

    dont see why not
    the code shouldnt really conflict with anything else

    trial and error i guess

  8. #8
    Registered User
    Join Date
    02-21-2013
    Location
    melbourne, victoria
    MS-Off Ver
    2010
    Posts
    28

    Re: Macro to check if Cell=today() then paste values in cells below

    Back again,

    Have been trying to get this to update when the report is refreshed.

    I've added the below to the worksheet that the update occurs on but now the code humdingaling provided is giving me an error method 'range' of object'_global' Failed on this this line of
    Code that is now providing the error: For i = 3 To Range("c12").End(xlToRight).Column 'last column in row 12

    Code that I'm using to make the macro run on update
    Please Login or Register  to view this content.

  9. #9
    Forum Expert
    Join Date
    08-12-2012
    Location
    Sydney, Australia
    MS-Off Ver
    Excel 2010
    Posts
    5,636

    Re: Macro to check if Cell=today() then paste values in cells below

    i put the worksheet calculate in the example
    does not have the same issue

    in your sheet
    is row C your header row for dates in your actual sheet?

    maybe include the sheet reference also

    Formula: copy to clipboard
    Please Login or Register  to view this content.


    replace sheet1 with your sheet name
    Last edited by humdingaling; 08-10-2014 at 08:58 PM.

+ 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] VBA macro to check if one cell has text and paste a formula in a different cell
    By vitt4300 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 04-10-2013, 01:38 PM
  2. [SOLVED] Macro w shortcut key to paste date 28 days from today into active cell
    By Zooka in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 02-07-2013, 06:08 PM
  3. [SOLVED] Macro - Copy and Combine values in cell and paste it in other cells based on Unique ID
    By haleakala17 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 12-11-2012, 05:41 PM
  4. Check if two cells are equal and copy,paste cell if true
    By solomeros in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 07-29-2011, 01:22 AM
  5. Check if two cells are equal, copy/paste adiacent cell
    By Macuil0101 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 07-15-2011, 12:40 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