+ Reply to Thread
Results 1 to 6 of 6

Inserting Formula Based On Another Cell Empty Or Not

  1. #1
    Registered User
    Join Date
    06-02-2014
    Location
    Oklahoma, USA
    MS-Off Ver
    2010
    Posts
    31

    Inserting Formula Based On Another Cell Empty Or Not

    I have a workbook that I am working on that I wish to insert a time stamp into a cell (on the same row) when there is a value present in column A (it will be a text value). I'm currently using the below code to do that. In the testing phase it worked fine as I entered in values in Column A one cell at a time.

    However, when I moved to pasting in several cells (several hundred) at one time, the time stamp was not added. I want it to be automatic and clear the cell when nothing is present in Column A but it has to work whether I enter one cell at a time or whether I paste in several cells at once. Im not sure if a loop needs to be use or what, but would appreciate any assistance.

    Please Login or Register  to view this content.

  2. #2
    Registered User
    Join Date
    06-02-2014
    Location
    Oklahoma, USA
    MS-Off Ver
    2010
    Posts
    31

    Re: Inserting Formula Based On Another Cell Empty Or Not

    Just thought I would check back and see if anyone had any input. Thanks.

  3. #3
    Registered User
    Join Date
    01-19-2015
    Location
    Poland
    MS-Off Ver
    2013
    Posts
    59

    Re: Inserting Formula Based On Another Cell Empty Or Not

    Hi,

    Why don't you try to use a function (instead of a procedure) which returns a date and as a parameter a cell is given. Take a look:
    Please Login or Register  to view this content.
    You call a function from your worksheet the same as a regular built-in function:

    Please Login or Register  to view this content.

  4. #4
    Valued Forum Contributor
    Join Date
    11-26-2012
    Location
    Sydney
    MS-Off Ver
    2010
    Posts
    419

    Re: Inserting Formula Based On Another Cell Empty Or Not

    If Target is a single cell, then Target.Value will return the value in that cell. When Target is a Range of cells, Target.Value doesn't really mean anything anymore, and will normally give you a Run-time error '13' Type Mismatch. The only reason it doesn't here is because of your On Error statement, which simply bypasses the offending line without telling you anything about it. The code in the error handler should only run if there is an error, so there should always be an Exit Sub above it.

    To do what you want, you need to do a For/Next loop to go through all the cells in the range, as shown below (note: I took out the UnProtect and Protect, as if I Protected my Worksheet at the end, I couldn't change it anymore to test - I'll assume your worksheet is set up to make that not a problem for you.)

    Please Login or Register  to view this content.

  5. #5
    Registered User
    Join Date
    06-02-2014
    Location
    Oklahoma, USA
    MS-Off Ver
    2010
    Posts
    31

    Re: Inserting Formula Based On Another Cell Empty Or Not

    Quote Originally Posted by rabbita View Post
    Hi,

    Why don't you try to use a function (instead of a procedure) which returns a date and as a parameter a cell is given. Take a look:
    Please Login or Register  to view this content.
    You call a function from your worksheet the same as a regular built-in function:

    Please Login or Register  to view this content.
    rabbita, thank you for your reply. I tried your suggestion but was not able to get it to work properly. I remembered, after trying your code, that I had tried something similar (using a function) and was not able to get it to work exactly as I had hoped. Its not an error in your code, its just the overall operation doesn't work as I would like. However, thank you very much for taking the time to post your idea.

  6. #6
    Registered User
    Join Date
    06-02-2014
    Location
    Oklahoma, USA
    MS-Off Ver
    2010
    Posts
    31

    Re: Inserting Formula Based On Another Cell Empty Or Not

    mgs73, thank you for your reply as well. I tried yours as well and it worked, particularly with pasting in data from another workbook. Thank you also for pointing out my lack of the Exit Sub statement. I am still very new at this and forgot about that. The funny thing about your comment about having to use a loop, I had made a comment to myself in the code when I first observed the procedure not working when I pasted data in, that I would likely have to use a loop to fix that.

    Thank you so very much for your help and I apologize it has taken me so long to get back here to reply. I had a few days off from work and, well, this project really did not cross my mind much, LOL.

+ 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. Replies: 1
    Last Post: 05-26-2014, 01:31 PM
  2. MACRO to empty a range of cells based on whether specified cell is empty
    By TBJV in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 05-01-2013, 10:35 PM
  3. Replies: 0
    Last Post: 08-21-2011, 11:53 AM
  4. Replies: 4
    Last Post: 06-24-2010, 11:13 AM
  5. Inserting a filename in a formula based on a cell
    By xxchrisukxx in forum Excel General
    Replies: 2
    Last Post: 08-15-2007, 08:40 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