Search TeachExcel.com
TeachExcel.com
TE
Teach Excel MS Office Tutorials Excel Consulting Services Excel Forum
Excel Video Tutorials Excel Tips Free Excel Macros Excel Help Resources Contact TeachExcel
Video Tutorials
  • Free Macros
  • Excel Help Directory
  • Excel 2007 Resources
  • Keyboard Shortcuts
  • Excel Forum
  • Contact/About

Macros
Excel Tutorials For Macros

WEEKNUM UDF for Excel Versions That Don't Contain This Function - UDF


Bookmark and Share

This is a WEEKNUM UDF for Excel. This allows you to determine the number of the week in the year on which a particular date falls. This UDF allows you to use the WEEKNUM function (standard in Excel 2007) in previous versions of Excel and across different regional versions or languages of Excel.

This function is exactly the same as the WEEKNUM() function in Excel 2007 and contains the same arguments in the same order.
Where to install the macro:  Module

WEEKNUM UDF for Excel Versions That Don't Contain This Function

Function WEEKNUMUDF(D As Date, FWDayArg As Integer) As Integer

WEEKNUMUDF = CInt(Format(D, "ww", FWDayArg))

End Function


Bookmark and Share


How to Install the Macro
  1. Select and copy the text from within the grey box above.

  2. Open the Microsoft Excel file in which you would like the Macro to function.

  3. Press "Alt + F11" - This will open the Visual Basic Editor - Works for all Excel Versions.  Or For other ways to get there, Click Here.

      For Excel Versions Prior to Excel 2007
      Go to Tools > Macros > Visual Basic Editor

      For Excel 2007
      Go to Office Button > Excel Options > Popular > Click Show Developer tab in the Ribbon. Then go to the Developer tab on the ribbon menu and on the far left Click Visual Basic

  4. On the new window that opens up, go to the left side where the vertical pane is located. Locate your Excel file; it will be called VBAProject (YOUR FILE'S NAME HERE) and click this.

  5. If the Macro goes in a Module, Click Here, otherwise continue to Step 8.

    1. Go to the menu at the top of the window and click Insert > Module
    2. Another window should have opened within the Visual Basic Editor's window. Within this new window, paste the macro code. Make sure to paste the code underneath the last line of anything else that is in the window.
    3. Go to Step 8.

  6. If the Macro goes in the Workbook or ThisWorkbook, Click Here, otherwise continue to Step 8.

    1. Directly underneath your excel file called VBAProject(your file's name here), click the Microsoft Excel Objects folder icon to open that drop-down list.
    2. Then, at the bottom of the list that appears, double-click the ThisWorkbook text.
    3. A new window inside the Visual Basic Editor's window will appear. In this new window, paste the code for the macro. Make sure to paste this code underneath the last line of any other code which is already in the window.
    4. Go to Step 8.

  7. If the Macro goes in the Worksheet Code, Click Here, otherwise continue to Step 8.

    1. Directly underneath your excel file called VBAProject(your file's name here), click the Microsoft Excel Objects folder icon to open that drop-down list.
    2. Within the list that appears you will see every worksheet that is in that excel file. They will be listed as such: Sheet1(NAME OF SHEET HERE) and under that will be Sheet2(NAME OF SHEET HERE). Select the sheet in which you want the macro to run and double-click that sheet.
    3. A new window inside the Visual Basic Editor's window will appear. In this new window, paste the code for the macro. Make sure to paste this code underneath the last line of any other code which is already in the window.
    4. Repeat steps b and c for every sheet you want the macro to work in. Putting the macro in one sheet will not enable it for any other sheets in the workbook.
    5. Go to Step 8.

  8. Close the Microsoft Visual Basic Editor window and save the Excel file. When you close the Visual Basic Editor window, the regular Excel window will not close.

  9. You are now ready to run the macro.



Similar Helpful Excel Resources

Weeknum Function Not Present In Excel 2002 - Excel

View Content
Hi All,
I find that in an Excel installation 2002 the function Weeknum is not present. Is it possible? How can I include it? Or where is the problem? Problem in settings?

Any help will be well appreciated.
Thanks in advance for your kind help.

Regards,

Giovanni

Will The Excel Weeknum Function Become Iso 8601 Compliant? - Excel

View Content
Will the Excel WEEKNUM function become ISO 8601 compliant?

This year we have to make work arounds for a lot of spreadsheets.
In Outlook you can choose the number method of weeks. This Excel function
should have an extra parameter to achieve this or an extension of the scope
of the present parameter.


Dont Know Excel Function - Excel

View Content
Dear All,

I have a table as follows:

Jul-04 1.0000
Aug-04 1.0025
Sep-04 1.0038
Oct-04 1.0046
Nov-04 1.0048
Dec-04 1.0110
Jan-05 1.0182
Feb-05 1.0261
Mar-05 1.0298
Apr-05 1.0336
May-05 1.0369
Jun-05 1.0403
Jul-05 1.0424
Aug-05 1.0450
Sep-05 1.0466
Oct-05 1.0480
Nov-05 1.0490
Dec-05 1.0525
Jan-06 1.0567
Feb-06 1.0621
Mar-06 1.0666
Apr-06 1.0699
May-06 1.0726
Jun-06 1.0747
Jul-06 1.0771
Aug-06 1.0814
Sep-06 1.0845
Oct-06 1.0861
Nov-06 1.0858

Jul-04 as Base Month.

What function to calculate that monthly escallation based on 3 or 3.5%
yearly (I am not which one of the rate)?

Thank you for your help.

Brgds,andri


Delete Row (vba) Function Doesn't Work On Some Excel Versions - Excel

View Content
Hi All,

I hope you are all ok?

I have the following VBA code in my excel sheet. Basically it searches a column for certain letters, and if it finds them it deletes the whole row with that letter in:

LR = Cells(Rows.Count, "A").End(xlUp).Row
For i = LR To 1 Step -1
If Not Cells(i, "A").Value = "T" Then Rows(i).EntireRow.Delete
Next i

Now this code works on all PC's in my office but 2. The 2 it doesn't work on, it seems to run extremely slow (i.e. deleting 1 row per 30-60 seconds). I have never allowed it to continue, I have always exited excel after 5 minutes waiting.

This runs extremely fast on the other PC's, running through and deleting all columns within 3-5 seconds. These PC's run excel 2003, while excel on the 2 it doesnt work on says it's 2002 (Office XP i think).

Does anyone know why this would be happening?

Regards

Rob McCarthy

Delete Row (vba) Function Doesn't Work On Some Excel Versions - Excel

View Content
Hi All,

I hope you are all ok?

I have the following VBA code in my excel sheet. Basically it searches a column for certain letters, and if it finds them it deletes the whole row with that letter in:

LR = Cells(Rows.Count, "A").End(xlUp).Row
For i = LR To 1 Step -1
If Not Cells(i, "A").Value = "T" Then Rows(i).EntireRow.Delete
Next i

Now this code works on all PC's in my office but 2. The 2 it doesn't work on, it seems to run extremely slow (i.e. deleting 1 row per 30-60 seconds). I have never allowed it to continue, I have always exited excel after 5 minutes waiting.

This runs extremely fast on the other PC's, running through and deleting all columns within 3-5 seconds. These PC's run excel 2003, while excel on the 2 it doesnt work on says it's 2002 (Office XP i think).

Does anyone know why this would be happening?

Regards

Rob McCarthy

Excel 2007 And Previous Versions Analisys Tool Pak Function - Excel

View Content
I have a file created in Excel previous to the 2007. This file contains Functions of the Analisys Tool Pak. One is installed Add-in corresponding. Nevertheless, I obtain error #Names. Recalculo the Leaf, F9 pulse and is not managed to update the formulas.
It's running "Compatibility Mode".

Only resource: to select the cells and to reenter the Formulas with CTRL+ENTER
Some idea better?

GALILEOGALI

Weeknum Function - Excel

View Content
This is regarding weeknum funtion of excel.
17 sep 2010 is on Wk 37.
But the function weeknum(a1) gives 38 in excel with A1 having 09.17.2010
Where am i making the mistake?

Weeknum Function - Excel

View Content
I've been creating a spreadsheet that takes figures from specific dates and summarises into weeks and came accross this problem..
E.g.

=WEEKNUM("20/9/2005")
returns '39'.. it is however week 38!

However, using dates from last year e.g.
=weeknum("14/10/2004")
it returns the correct week 42.

Is it me or is this a bug?... i've tried looking for some sort of patch but no joy!

Weeknum Function In Vba - Excel

View Content
Hi All,

I'd like to use WeekNum function in MS Query. Unforturnately, WeekNum is only a WorksheetFunction and thus cannot be used in MS Query. How could I build a similar function with VBA functions..?

Thanks for help!

-Jack

Function Weeknum #n/a - Excel

View Content
I have a problem with the function weeknum.

In the merged cell A4:B4 I have a date field which is formated to display "Dated : "dd mmmm yyyy. In the merged cell A2:E2, I have the function =weeknum(A4-4) with a cell format "Week "0.

My problem is that recently, after I've emailed the file to my friend, I get an error when I open the file "File error: data may have been lost." I could only click on OK.

In my merged cell A2:E2, it still display Week 11 but I lost my function in the cell. The function would show =#N/A and if I go to A2:E2 and do F2 Enter, the cell would change from Week 11 to #N/A.

I did not have problem with this before and I've been having this formula since 2007. This problem started recently, only in the month of March 2009.

I would appreciate it if someone could help me.

Random Tutorials
Make a Thermometer Style Chart in Excel
(Intermediate)
Extract Text from Cells - Intermediate Example
(Intermediate)
IF Statement Introduction & Using Nested IF's
(Easy)
HLOOKUP() Function - Introduction
(Intermediate)
AND(), OR(), and IF() Statements/Formulas
(Intermediate)
Link Cells Between Worksheets
(Easy)
Submit Inquiry Here
  • Prices From $10
Name:*
E-mail:*
Request:*
The macro(s) on this page will be sent with the request.
Contact | Privacy Policy | Disclaimer
Copyright© 2012 TeachExcel.com