+ Reply to Thread
Results 1 to 4 of 4

VBA not bringing back the correct date

  1. #1
    Forum Contributor
    Join Date
    09-03-2012
    Location
    Newcastle
    MS-Off Ver
    Excel 2010
    Posts
    132

    VBA not bringing back the correct date

    Hi,

    So i'm currently using this in VBA:

    Please Login or Register  to view this content.
    This SHOULD bring back: ("Y:\X\X\X\September\SPR Information (Sep-2013).xls)

    But for some reason today it's bringing back: ("Y:\X\X\X\October\SPR Information (Oct-2013).xls)


    Any idea why this is doing this.. it was working fine yesterday, but today its thinking that the month is November?

    I've also tried changing -1 to -2, and thats bringing back August so thats a bit weird!

    Any help - cheers!

  2. #2
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,644

    Re: VBA not bringing back the correct date

    If you always want the previous month tryDateSerial(Year(Date), Month(Date), 0) or MonthName(Month(Date)-1) for the full month name or MonthName(Month(Date)-1, True) for the abbreviated month name.
    If posting code please use code tags, see here.

  3. #3
    Forum Expert
    Join Date
    11-29-2010
    Location
    Ukraine
    MS-Off Ver
    Excel 2019
    Posts
    4,168

    Re: VBA not bringing back the correct date

    hi jonathan.haynes, you could use this:

    Please Login or Register  to view this content.
    instead of this:

    Please Login or Register  to view this content.
    Re your issue with the month. When Excel calculates your Format string it gets this:
    year - 2013
    month - 9
    date - 31
    It considers this to be 01/10/2013. Yesterday we had 30th of October. As September has 30 days it worked fine. Will work fine again tomorrow less 2

  4. #4
    Forum Contributor
    Join Date
    09-03-2012
    Location
    Newcastle
    MS-Off Ver
    Excel 2010
    Posts
    132

    Re: VBA not bringing back the correct date

    Thanks both!

+ 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] Stop Vlookup bringing back 0's or #REF! and bring back blanks instead
    By Carling73 in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 05-30-2013, 04:43 PM
  2. [SOLVED] Excel 2007 : Bringing Back the final date/time combo of multiple calls
    By Icehockey44 in forum Excel General
    Replies: 9
    Last Post: 05-24-2012, 05:27 AM
  3. [SOLVED] Simple VLOOKUP not bringing back correct results
    By AL2275 in forum Excel General
    Replies: 6
    Last Post: 04-30-2012, 09:32 AM
  4. Excel 2007 : Lookup - bringing back more than one value
    By csalcido in forum Excel General
    Replies: 2
    Last Post: 04-23-2012, 01:59 PM
  5. Excel 2007 : Vlookup not bringing back correct data
    By voviedo in forum Excel General
    Replies: 2
    Last Post: 01-26-2010, 11:27 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