troubleshooting Question

VBA User Definded Types

Avatar of mcs26
mcs26 asked on
Programming Languages-OtherVisual Basic ClassicMicrosoft Applications
4 Comments1 Solution288 ViewsLast Modified:

I'm little confused as to why the function below does not work. The error message is, Compile Error: User-defined type is not defined. What's strange is if a turn the function into a sub instead and take out the last line, BenchmarkDates = BMDates
the code works and recognises the user defined type.

Use user defined types a lot in the same module and have no issues?

Thanks for any help,

Private Type TypeBMDates
    YTD As Date
    MTD As Date
    TMinus5 As Date
    TMinus1 As Date
End Type

Function BenchmarkDates() As TypeBMDates

Dim BMDates As TypeBMDates

    BMDates.YTD = DateSerial(Year(Now), 1, 0)
    BMDates.YTD = Last_Working_Day(BMDates.YTD)
    BMDates.MTD = DateSerial(Year(Now), Month(Now), 0)
    BMDates.MTD = Last_Working_Day(BMDates.MTD)
    BMDates.TMinus5 = Last_Working_Day(DateAdd("d", -7, Date))
    BMDates.TMinus1 = Last_Working_Day(DateAdd("d", -1, Date))

    BenchmarkDates = BMDates
    End Function

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 1 Answer and 4 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 4 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros