convert function to a Sub

Pookiemeister

Well-known Member
Joined
Jan 6, 2012
Messages
626
Office Version
  1. 365
  2. 2010
Platform
  1. Windows
I found this function that calculates the week of a month and it works great on a spreadsheet but I need to work on a userform.
Code:
Function WeekOfMonth(dDate1 As Date) As String    Dim dDate2 As String
    Dim wWeek As Integer
    
    'dDate2 is changed to date from String
     
    dDate2 = VBA.CDate(Month(dDate1) & "/01/" & Year(dDate1))
    wWeek = DateDiff("ww", dDate2, dDate1.Value, vbSunday, vbUseSystem) + 1
     
     'Return the Week number of the month
     'Monday is taken as week starting date, you can change
     'it to your desired day as starting date of week
         
    WeekOfMonth = wWeek
    
End Function
The date will be coming from the DTPicker1 value and the WeekOfMonth will be displayed inside lblWotM.caption on the UserForm1.

Thanks
 

Excel Facts

Lock one reference in a formula
Need 1 part of a formula to always point to the same range? use $ signs: $V$2:$Z$99 will always point to V2:Z99, even after copying
Code:
lblWotM.caption = WeekOfMonth(CDate(DTPicker1))
 
Last edited:
Upvote 0

Forum statistics

Threads
1,223,705
Messages
6,173,989
Members
452,541
Latest member
haasro02

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top