+ Reply to Thread
Results 1 to 2 of 2

dateAdd Overflow

Hybrid View

  1. #1
    Registered User
    Join Date
    08-20-2013
    Location
    San Diego, CA
    MS-Off Ver
    Excel 2010
    Posts
    6

    dateAdd Overflow

    I keep getting an overflow on the following code when it attempts to run the dateAdd function. I've looked through the excel help and I can't figure out what I'm doing wrong. I know it's probably something easy, but a fresh set of eyes would be appreciated.
    Sub SetDate()
    Dim currentDay As Date
    Dim dayOfWeek, statusDay As Integer
    
        currentDay = Now
        dayOfWeek = DateDiff("d", "8/26/2013", currentDay) Mod 7
        Select Case dayOfWeek
            Case 0
                statusDay = currentDay
            Case 1
                statusDay = DateAdd("d", -1, currentDay)
            Case 2
                statusDay = DateAdd("d", -2, currentDay)
            Case 3
                statusDay = DateAdd("d", -3, currentDay)
            Case 4
                statusDay = DateAdd("d", -4, currentDay)
            Case 5
                statusDay = DateAdd("d", -5, currentDay)
            Case 6
                statusDay = DateAdd("d", -6, currentDay)
        End Select
    End Sub
    Last edited by rmweaver81; 09-03-2013 at 01:16 PM.

  2. #2
    Registered User
    Join Date
    08-20-2013
    Location
    San Diego, CA
    MS-Off Ver
    Excel 2010
    Posts
    6

    Re: dateAdd Overflow

    I'm an idiot. statusDay needs to be set as a Date, not an Integer. Sorry all.

+ 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: 3
    Last Post: 12-29-2011, 08:07 AM
  2. DateAdd problem
    By si666 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 05-20-2011, 06:58 AM
  3. Overflow on .Top = .Top + x
    By Doctorul in forum Excel Charting & Pivots
    Replies: 7
    Last Post: 05-19-2009, 05:00 AM
  4. [SOLVED] DateAdd
    By johnboy in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 06-17-2006, 06:10 PM
  5. Help with VBA (or VB) DateAdd, WORDAY functions, date format
    By Kind writer/user/programmer in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 01-08-2005, 07:07 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