+ Reply to Thread
Results 1 to 7 of 7

VBA code to look at a column and see if nil or not, if nil, to add the current date.

  1. #1
    Registered User
    Join Date
    11-15-2013
    Location
    London
    MS-Off Ver
    Excel 2003
    Posts
    31

    Unhappy VBA code to look at a column and see if nil or not, if nil, to add the current date.

    Hi all,

    I have a problem I'm sure is probably pretty simple but I'm having some issues wrapping my head around it.

    I have a script that essentially sends an email based on what is in 2 different column's cells if the current date is equal to the 'date received' column.

    However, I'd like to change this to a 'Date Sent' column and want the macro to look at the cell, if it's empty - add the date and send. If the cell is not empty, I want it to ignore it.

    The current script I have is shown below. Any help on this would be greatly appreciated!

    Kind regards,
    MW

    Please Login or Register  to view this content.

  2. #2
    Valued Forum Contributor
    Join Date
    09-21-2011
    Location
    Birmingham UK
    MS-Off Ver
    Excel 2003/7/10
    Posts
    2,188

    Re: VBA code to look at a column and see if nil or not, if nil, to add the current date.

    You need to change this line

    If Sheets("Home").Cells(i, 1).Value = (Date) Then

    without seeing your sheet, we cant determine what column your Date Sent column is. Also, this only checks one column, column A for a value of todays date.

    YOu could have done some investigation on this matter, pretty easy to change the IF, research what is going on.
    Hope this helps

    Sometimes its best to start at the beginning and learn VBA & Excel.

    Please dont ask me to do your work for you, I learnt from Reading books, Recording, F1 and Google and like having all of this knowledge in my head for the next time i wish to do it, or wish to tweak it.
    Available for remote consultancy work PM me

  3. #3
    Registered User
    Join Date
    11-15-2013
    Location
    London
    MS-Off Ver
    Excel 2003
    Posts
    31

    Re: VBA code to look at a column and see if nil or not, if nil, to add the current date.

    Hi Nathan,

    I've been trying to change that line into what it should be but kept getting run time errors stating there must be at least one name or contact group in the To, Cc, or Bcc

    The columns are arranged as follows:

    Column A - Date Recieved
    Column B - Subject
    Column C - Event
    Column D - Actionee
    Column E - Date Email Sent
    Column F - reminder column
    Column G - Email Address

    My biggest concern is that it'll look at ALL the empty cells in the column and add today's date which then defeats the purpose the next day when new entries come in..


    Kind regards,
    MW

  4. #4
    Valued Forum Contributor
    Join Date
    09-21-2011
    Location
    Birmingham UK
    MS-Off Ver
    Excel 2003/7/10
    Posts
    2,188

    Re: VBA code to look at a column and see if nil or not, if nil, to add the current date.

    Please Login or Register  to view this content.

  5. #5
    Registered User
    Join Date
    11-15-2013
    Location
    London
    MS-Off Ver
    Excel 2003
    Posts
    31

    Re: VBA code to look at a column and see if nil or not, if nil, to add the current date.

    Aw, excellent. Cheers Nathan, I've tested this and it works perfectly. I've also in the mean time tried a
    Please Login or Register  to view this content.
    Which seems to have worked as well (for anyone looking for something like this)

    Appreciate your time Nathan, thanks!

    Kind regards,
    Martin W

  6. #6
    Valued Forum Contributor
    Join Date
    09-21-2011
    Location
    Birmingham UK
    MS-Off Ver
    Excel 2003/7/10
    Posts
    2,188

    Re: VBA code to look at a column and see if nil or not, if nil, to add the current date.

    No worries. Try using UsedRange instead of defining columns as full row length, yours for example will be semi-redundant in 2007+ as it has more rows than 65K.

    Enjoy!!!!

  7. #7
    Registered User
    Join Date
    11-15-2013
    Location
    London
    MS-Off Ver
    Excel 2003
    Posts
    31

    Re: VBA code to look at a column and see if nil or not, if nil, to add the current date.

    Ah I see what you mean, thanks for the tip! If I use UsedRange, will it still be backwards compatible with older versions? Some people seem to be using ancient Excel versions =/

  8. #8
    Valued Forum Contributor
    Join Date
    09-21-2011
    Location
    Birmingham UK
    MS-Off Ver
    Excel 2003/7/10
    Posts
    2,188

    Re: VBA code to look at a column and see if nil or not, if nil, to add the current date.

    No worries. Try using UsedRange instead of defining columns as full row length, yours for example will be semi-redundant in 2007+ as it has more rows than 65K.

    Enjoy!!!!

+ 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] code that will check the date from a table if its MM/YY is current and if not then date=YY
    By richzter in forum Excel Programming / VBA / Macros
    Replies: 12
    Last Post: 05-24-2014, 10:27 PM
  2. 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
  3. Vba to subtract current date from date in column G and put static diff in column H
    By jtyoder in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 05-31-2013, 02:55 PM
  4. [SOLVED] add current time (hh:mm:ss) as well as current date (dd:mm:yyyy) into the code
    By papasideris in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 04-28-2012, 02:29 PM
  5. [SOLVED] Q. How do I code a column to insert current date, when I double-click?
    By George in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 06-07-2005, 12:05 PM

Tags for this Thread

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