VBA textbox to display weeknumber

PLwolves87

New Member
Joined
Jan 6, 2023
Messages
31
Office Version
  1. 365
Platform
  1. Windows
hi All,

so ive made a pop-up calendar userform, when you select the date of choice this date is then displayed on the main userform in a textbox, for example you click on the calendar and select 01/01/2023 then click the command button to confirm this date and then it closes the calendar and on the main userform textbox1 will display the date from your calendar choice (it is displayed as "01 January 2023" not 01/01/2023) but then ive added textbox2 which will be for the week number of the date selected. week numbers must start from the first monday of the year.

does anyone know what code i would use to display the weeknumber in textbox2 from the date selected in textbox1

TEXTBOX1= 'calendar date which has been selected
TEXTBOX2 = 'week number from textbox1

thanks
 

Excel Facts

Excel Wisdom
Using a mouse in Excel is the work equivalent of wearing a lanyard when you first get to college
Hi
Assuming Sunday is the first day of the week, then try the following

VBA Code:
With Me.TextBox1
        If IsDate(.Value) Then Me.TextBox2.Value = Application.WeekNum(DateValue(.Value), vbSunday)
    End With

If Monday is the first day then change vbSunday to vbMonday

Dave
 
Upvote 0

Forum statistics

Threads
1,223,386
Messages
6,171,790
Members
452,424
Latest member
Sheila003

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