+ Reply to Thread
Results 1 to 8 of 8

Retrieve last day of the month but hitting error

  1. #1
    Registered User
    Join Date
    09-04-2014
    Location
    Australia
    MS-Off Ver
    Mac 2011
    Posts
    2

    Unhappy Retrieve last day of the month but hitting error

    Hi,

    I have month and year in the worksheet where I allowed user to select Month and Year and I wanted to retrieve last day of the Month+Year selected.
    see below codes
    Dim Month As String
    Dim Year As String
    Dim EndDate As Date

    Month = Range("B1").Value 'July
    Year = Range("D1").Value '2014

    EndDate = DateValue((Month + 1) & "/1/" & Year) - 1

    Hitting runtime error '13' : Type mismatch. What am I doing wrong? Please help.

  2. #2
    Forum Expert Solus Rankin's Avatar
    Join Date
    05-24-2013
    Location
    Hollywood, CA
    MS-Off Ver
    Win7 Office 2010 VS Express 2012
    Posts
    2,655

    Re: Retrieve last day of the month but hitting error

    Are the values in B1 and D1 text or numbers?
    Thanks,
    Solus


    Please remember the following:

    1. Use [code] code tags [/code]. It keeps posts clean, easy-to-read, and maintains VBA formatting.
    Highlight the code in your post and press the # button in the toolbar.
    2. Show appreciation to those who have helped you by clicking below their posts.
    3. If you are happy with a solution to your problem, mark the thread as [SOLVED] using the tools at the top.

    "Slow is smooth, smooth is fast."

  3. #3
    Forum Expert
    Join Date
    06-25-2009
    Location
    Sofia, Bulgaria, EU
    MS-Off Ver
    Excel 2003-2013
    Posts
    1,290

    Re: Retrieve last day of the month but hitting error

    Hi,
    first of all, please use
    Please Login or Register  to view this content.
    if you declare Year and Month as Integers, you can skip type conversion.
    If you are pleased with a member's answer then use the Star icon to rate it.

  4. #4
    Forum Expert MickG's Avatar
    Join Date
    11-23-2007
    Location
    Banbury,Oxfordshire
    Posts
    2,650

    Re: Retrieve last day of the month but hitting error

    If you month "July" in "B1" is a string then ,Perhaps
    Please Login or Register  to view this content.
    Regards Mick

  5. #5
    Forum Expert MickG's Avatar
    Join Date
    11-23-2007
    Location
    Banbury,Oxfordshire
    Posts
    2,650

    Re: Retrieve last day of the month but hitting error

    If you month "July" in "B1" is a string then ,Perhaps
    Please Login or Register  to view this content.
    Regards Mick

  6. #6
    Registered User
    Join Date
    09-04-2014
    Location
    Australia
    MS-Off Ver
    Mac 2011
    Posts
    2

    Re: Retrieve last day of the month but hitting error

    Hi all,
    Thanks for your reply. Sorry it's my first time posting. Will take note of that.

    I'm hitting error type mismatch for both codes below. Month and Year is a String. I'm using Excell 2011 on Mac. Is that the problem?

    I tried
    Please Login or Register  to view this content.
    and also

    Please Login or Register  to view this content.

  7. #7
    Forum Expert MickG's Avatar
    Join Date
    11-23-2007
    Location
    Banbury,Oxfordshire
    Posts
    2,650

    Re: Retrieve last day of the month but hitting error

    I'm not familar with "Mac's " and Excel, although it may be the case.
    I can only suggest you open the VB Code Window and step through the code (Clicking "F8") to see where it fails.
    If you click help in the Vb Code Window I imagine you can see if those Functions like "Month" and "DateAdd" are supported.

  8. #8
    Forum Expert
    Join Date
    06-25-2009
    Location
    Sofia, Bulgaria, EU
    MS-Off Ver
    Excel 2003-2013
    Posts
    1,290

    Re: Retrieve last day of the month but hitting error

    Hi,
    it's because you have "July" in B1. My understanding was that you have Month index i.e. 7.
    add this to your module
    Please Login or Register  to view this content.
    Amend your code as follows:

    Please Login or Register  to view this content.

+ 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] Error when hitting cancel on Application.InputBox
    By wigtown_deano in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 08-05-2013, 05:26 AM
  2. Error 1004 - hitting a key in a dropdown list of a userform
    By ggabi in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 01-20-2012, 06:19 AM
  3. retrieve month
    By benj in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 02-21-2005, 12:16 AM
  4. retrieve month
    By benj in forum Excel General
    Replies: 1
    Last Post: 02-18-2005, 05:29 AM
  5. retrieve month
    By benj in forum Excel General
    Replies: 2
    Last Post: 02-18-2005, 05:23 AM

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