Get the week number of a given date

sofas

Well-known Member
Joined
Sep 11, 2022
Messages
559
Office Version
  1. 2021
  2. 2019
Platform
  1. Windows
Welcome . Cell A2 contains a date in the format yyyy/mm/dd. I want to extract the week number in cell D4.
I found the solution using formulas, but I need to use the VBA code with the possibility of changing the start day of the week. Suppose the first day of the week is Friday.
 

Excel Facts

Test for Multiple Conditions in IF?
Use AND(test, test, test, test) or OR(test, test, test, ...) as the logical_test argument of IF.
How about
VBA Code:
Sub MM1()
Dim d As Integer
d = InputBox("please insert a number from 1 to 7")
Cells(4, 4).Formula = "=weeknum(a2," & d & ")"
End Sub
 
Upvote 0
Sorry, Friday will be 6 in the InputBox not 1 !!
 
Upvote 0
Sorry, Friday will be 6 in the InputBox not 1 !!
Unfortunately, cell d4 remains empty!!! Is it possible to extract the week number in msgbox , for example, for testing? Only because I will then install the beginning of the week number that suits me inside the code and dispense with the checkbox if it works well.
 
Upvote 0
It could be the date format you are using
You might need to insert a line before the input box Lin.
Range(A2, number format = "dd/mm/yyyy")
 
Upvote 0
Oops typo...I'm on my phone
Range("A2").numberformat="dd/mm/yyy"
 
Upvote 0
It could be the date format you are using
You might need to insert a line before the input box Lin.
Range(A2, number format = "dd/mm/yyyy")
Maybe because my format is like this: yyyy/dd/mm. I have previously obtained some solutions, but they only work with the dd/mm/yyyy format. Perhaps there is a solution to circumvent this, but I am unable to do it.
 
Upvote 0

Forum statistics

Threads
1,223,897
Messages
6,175,269
Members
452,628
Latest member
dd2

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