+ Reply to Thread
Results 1 to 14 of 14

VBA code if value is typed or pasted in a cell then current date is returned

  1. #1
    Registered User
    Join Date
    05-17-2020
    Location
    Philippines
    MS-Off Ver
    2016
    Posts
    35

    VBA code if value is typed or pasted in a cell then current date is returned

    Hi!

    I have a sheet that is automatically populated from another sheet that is triggered by the user. I need the corresponding cell in column E to give the current date if a cell in Column A (starting from A4) is not empty (if a value has been typed or entered). In the same manner, column F should give the "tab name".

    Example:
    Tab name is "Terminated"
    Column A is Employee Id
    Column E is date of termination
    Column F is Employee Status (need to have this column for other reports)

    I have a macro button to automatically move employees from the "Active" tab to the "Terminated" tab. Once moved (I assume this is being copy-pasted but in case macro fails or user wants to type manually, I need it to work either way) I need column E to have the termination date and column F the employee status (which can be copied from Tab name or can also be specified in the code -- whatever works easiest)

    I mentioned "typed or entered" because I have read from other sites that sometimes the macro does not run if value is pasted.

    Thank you in advance!
    Last edited by Roux11; 05-25-2020 at 04:46 AM.

  2. #2
    Valued Forum Contributor Eastw00d's Avatar
    Join Date
    02-29-2020
    Location
    Breda, NL
    MS-Off Ver
    2016, 2019
    Posts
    833

    Re: VBA code if value is typed or pasted in a cell then current date is returned

    Maybe you can work with this:
    Please Login or Register  to view this content.
    to be placed in a worksheet module.

    Cheers
    Erwin
    I started learning VBA because I was lazy ...
    Still developing.... being more lazy...

  3. #3
    Registered User
    Join Date
    05-17-2020
    Location
    Philippines
    MS-Off Ver
    2016
    Posts
    35

    Re: VBA code if value is typed or pasted in a cell then current date is returned

    Thank you sir. Works well whey typing data to column A but does not work if data is pasted to column A.

  4. #4
    Valued Forum Contributor Eastw00d's Avatar
    Join Date
    02-29-2020
    Location
    Breda, NL
    MS-Off Ver
    2016, 2019
    Posts
    833

    Re: VBA code if value is typed or pasted in a cell then current date is returned

    Strange, for me the pasting is working, but the line CurRow = ActiveCell.Row - 1,
    has to change into
    Please Login or Register  to view this content.
    Cheers
    Erwin

  5. #5
    Registered User
    Join Date
    05-17-2020
    Location
    Philippines
    MS-Off Ver
    2016
    Posts
    35

    Re: VBA code if value is typed or pasted in a cell then current date is returned

    Also, if the value is deleted, the date does not disappear.

  6. #6
    Valued Forum Contributor Eastw00d's Avatar
    Join Date
    02-29-2020
    Location
    Breda, NL
    MS-Off Ver
    2016, 2019
    Posts
    833

    Re: VBA code if value is typed or pasted in a cell then current date is returned

    That, was a requirement you did not ask, but here you are:
    Please Login or Register  to view this content.
    Cheers
    Erwin

  7. #7
    Registered User
    Join Date
    05-17-2020
    Location
    Philippines
    MS-Off Ver
    2016
    Posts
    35

    Re: VBA code if value is typed or pasted in a cell then current date is returned

    The new code with the If Cells(CurRow, 1) <> "" Then statement doesn't seem to work.

  8. #8
    Valued Forum Contributor Eastw00d's Avatar
    Join Date
    02-29-2020
    Location
    Breda, NL
    MS-Off Ver
    2016, 2019
    Posts
    833

    Re: VBA code if value is typed or pasted in a cell then current date is returned

    Something strange is going on then.
    Please could you upload your workbook, without confidential data of course, with the code that gives an error?

    Cheers
    Erwin

  9. #9
    Registered User
    Join Date
    05-17-2020
    Location
    Philippines
    MS-Off Ver
    2016
    Posts
    35

    Re: VBA code if value is typed or pasted in a cell then current date is returned

    So I did another test and you were right, pasting values work (using ctrl + V). However, i have a macro that does that automatically, copying data from one sheet to another and that isn't working with our code here to insert date and status. I do not know if we have to tweak the copy code or the insert date code but here is the code that I have to copy data for your reference:

    Please Login or Register  to view this content.

  10. #10
    Forum Expert Arkadi's Avatar
    Join Date
    02-13-2014
    Location
    Smiths Falls, Ontario, Canada
    MS-Off Ver
    Office 365
    Posts
    5,059

    Re: VBA code if value is typed or pasted in a cell then current date is returned

    Sheet changes caused by VBA don't trigger worksheet change events. You may want to incorporate the code into your existing module.
    Please help by:

    Marking threads as closed once your issue is resolved. How? The Thread Tools at the top
    Any reputation (*) points appreciated. Not just by me, but by all those helping, so if you found someone's input useful, please take a second to click the * at the bottom left to let them know

    There are 10 kinds of people in this world... those who understand binary, and those who don't.

  11. #11
    Valued Forum Contributor Eastw00d's Avatar
    Join Date
    02-29-2020
    Location
    Breda, NL
    MS-Off Ver
    2016, 2019
    Posts
    833

    Re: VBA code if value is typed or pasted in a cell then current date is returned

    @Arkadi, I agree with you, but the OP didn't specify that.
    @Roux11, perhaps if you add these lines just before the "EntireRow.Delete"-line:
    Please Login or Register  to view this content.
    cheers
    Erwin
    Last edited by Eastw00d; 05-29-2020 at 02:12 AM.

  12. #12
    Forum Expert Arkadi's Avatar
    Join Date
    02-13-2014
    Location
    Smiths Falls, Ontario, Canada
    MS-Off Ver
    Office 365
    Posts
    5,059

    Re: VBA code if value is typed or pasted in a cell then current date is returned

    @Eastw00d no worries! It wasn't a negative comment, I was just explaining it to the OP

  13. #13
    Registered User
    Join Date
    05-17-2020
    Location
    Philippines
    MS-Off Ver
    2016
    Posts
    35

    Re: VBA code if value is typed or pasted in a cell then current date is returned

    It didn't work, @Eastwo0d but thank you so much for all your help. I will just have this manually entered. Cheers

  14. #14
    Valued Forum Contributor Eastw00d's Avatar
    Join Date
    02-29-2020
    Location
    Breda, NL
    MS-Off Ver
    2016, 2019
    Posts
    833

    Re: VBA code if value is typed or pasted in a cell then current date is returned

    my mistake, it should be:
    Please Login or Register  to view this content.
    Cheers
    Erwin

+ 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] Format date returned by sheet code
    By fpt264 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 08-12-2019, 05:34 AM
  2. Run macro when data based on cell value that is pasted and not typed in
    By originalJ in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 03-02-2016, 01:56 PM
  3. Code to update cell with current date & time when other cells are modified
    By gjtbackwards in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 03-12-2014, 07:54 PM
  4. Can Macros be set to automatically run when something is pasted or typed into a cell?
    By Lylestyle89 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 11-25-2013, 09:06 PM
  5. Code to insert current date (but NOT current time)
    By mjwillyone in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 09-13-2013, 09:37 AM
  6. [SOLVED] VBA code for cell date is less than current date + 2months
    By craigten in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 05-07-2013, 09:21 AM
  7. How do I code a cell to display the current date on double-click?
    By George in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 05-14-2005, 01:06 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