+ Reply to Thread
Results 1 to 5 of 5

VBA help with recognizing date properly

  1. #1
    Registered User
    Join Date
    03-01-2016
    Location
    New Jersey
    MS-Off Ver
    2013
    Posts
    47

    VBA help with recognizing date properly

    Hi all,

    I am having a problem with a VBA code I wrote. This code looks at column H and if there is a date formatted as DD-MM-YYYY and the YYYY is equal to the current year, it puts a "N" in the corresponding cell of column Z. If the YYYY is from the previous year, it puts a "Y" in the corresponding cell of column Z. If neither criteria are met, it puts a "?".

    The problem i am having is that the code doesn't seem to loop through after it enters a "Y" or an "N". It just seems to keep putting a "Y" or an "N" in each cell of column Z until it finds a new criteria that it meets. Can anyone see something wrong with this code that it wouldn't work correctly?

    Please Login or Register  to view this content.

  2. #2
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,447

    Re: VBA help with recognizing date properly

    This works for me but I don't have YOUR data to test it on:

    Please Login or Register  to view this content.
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


  3. #3
    Registered User
    Join Date
    03-01-2016
    Location
    New Jersey
    MS-Off Ver
    2013
    Posts
    47

    Re: VBA help with recognizing date properly

    So I replaced my code with the one you gave me and I am getting a For without Next error. Here is all of my code. I changed your code slightly since I was already using For Row, so I changed it to For Row4 and Next Row4. Any idea why I am getting the For without Next error

    Please Login or Register  to view this content.

  4. #4
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,447

    Re: VBA help with recognizing date properly

    My code works as a self contained entity. I created an empty workbook and adapted your code to test a loop. It works, therefore, you must have changed YOUR code when you incorporated it. Clearly, your routine is more complex/repetitive than the sample you posted and which I modified.

    I can't test your code because I don't have the data and/or workbooks which it requires to run
    Attached Files Attached Files

  5. #5
    Forum Expert leelnich's Avatar
    Join Date
    03-20-2017
    Location
    Delaware, USA
    MS-Off Ver
    Office 2016
    Posts
    2,807

    Re: VBA help with recognizing date properly

    RE : "For without Next"
    Your final "Next" statement is commented out. Remove the leading apostrophe, right?
    Please Login or Register  to view this content.
    This is my first post. Hope it helps

+ 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] Cubevalue not recognizing Date SOLVED
    By sambuka in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 06-04-2016, 11:54 AM
  2. [SOLVED] Recognizing a date format to calculate date in the future
    By Nole68 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 12-30-2015, 12:51 PM
  3. recognizing the first of the month in a cell containing the date
    By jsnclns in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 07-24-2013, 01:21 PM
  4. Recognizing date with VBA
    By walduxas in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 06-21-2013, 01:50 AM
  5. Excel not recognizing date input
    By xaver in forum Excel General
    Replies: 3
    Last Post: 09-23-2008, 08:14 AM
  6. Formula recognizing date range?
    By briannerene in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 09-25-2007, 10:55 PM
  7. Excel not recognizing Dates properly.
    By Dan in forum Excel General
    Replies: 1
    Last Post: 03-23-2005, 04:06 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