Solved

VBA Excel 2000 - Week number

Posted on 2011-03-17
8
428 Views
Last Modified: 2012-05-11
Dear Experts,

I have a short code part which works fine for days and months from todays date

Dim SaveFileDay As String
Dim SaveFileMonth As String
SaveFileDay = Day(Date)
SaveFileMonth = Month(Date)

I would like to do the same but for weeks so determining the current number of week from todays date, but I am not sure in the syntax as the below logic does not work

Dim SaveFileWeek As String
SaveFileWeek = Weeknum(Date)

Could you please advise how it should be?

thanks,
0
Comment
Question by:csehz
  • 5
  • 3
8 Comments
 
LVL 41

Expert Comment

by:dlmille
ID: 35155276
Try:

SaveFileWeek = application.WorksheetFunction.WeekNum(Date)


Dave
0
 
LVL 41

Expert Comment

by:dlmille
ID: 35155283
PS - if you use the HELP (F1) in the VBA Project area, you can look up:  WorksheetFunction Object Members and then drill down on that to see all the worksheet functions that are available to you.

Cheers,

Dave
0
 
LVL 1

Author Comment

by:csehz
ID: 35155337
Dave thanks, applying this row I got error message that

Object does not support this property or method

I assume it is because like on the attached picture, maybe in Excell 2000 the Weeknum is not available? In that case do you have maybe some alternative solution?
wsf.jpg
0
 
LVL 41

Expert Comment

by:dlmille
ID: 35155341
Try APPLICATION.Worksheetfunction ?
0
Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

 
LVL 41

Accepted Solution

by:
dlmille earned 500 total points
ID: 35155350
Sorry...

This link should get you what you need, if you have to build the weeknum function, yourself:

http://www.cpearson.com/excel/WeekNumbers.aspx

dave
0
 
LVL 1

Author Closing Comment

by:csehz
ID: 35155380
Dave thanks, it is interesting that anyway as normal function in a cell that works for me, so finally applied this

SaveFileWeek = Evaluate("=WEEKNUM(TODAY())")

thanks just again,
0
 
LVL 41

Expert Comment

by:dlmille
ID: 35155411
Good one.  I've recently (today) had problems with Evaluate in a macro (run many,many times appears to create excel/display/memory errors).

One potential alternative to evaluate is the following:

 
Function myEvaluate(testStr As String, fromMacro As Boolean) As Boolean
'attempt to do a better job than Application.Evaluate to evaluate these operations, as the Excel 4.0 macro calls (lots of them) create memory errors

    myEvaluate = False
      
    'First, check to see if this is a worksheet function, or is running from a macro
    
    'fall thru with FALSE evaluation on comparisons that don't make sense - e.g., comparing a string with a numeric equality
    On Error Resume Next
    If fromMacro Then 'must be running from a macro so leveraging defined name OK
        ActiveWorkbook.Names.Add Name:="toEvaluate", RefersToR1C1:="=False"
    
        ActiveWorkbook.Names("toEvaluate").RefersTo = "=" & testStr
        
        myEvaluate = [toEvaluate]
        
        ActiveWorkbook.Names("toEvaluate").Delete
    Else 'must be running as a worksheet function, so should be "safer" to run as-is with evaluate, as can't make defined name at this level
        myEvaluate = Application.Evaluate(testStr)
    End If
    
    If Err.Number <> 0 Then
        myEvaluate = False
    End If
    Err.Clear
    On Error GoTo 0
    
End Function

Open in new window


Dave
0
 
LVL 1

Author Comment

by:csehz
ID: 35155441
Thanks the info, good to know..
0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

INDEX and MATCH can be used to great effect to replace HLOOKUP and VLOOKUP as it does not have the limitation of needing the data to be sorted so that the reference value is in the first column or row. It also has the ability to perform a bi-directi…
Improved? Move/Copy Add-in Replacement - How to avoid the annoying, “A formula or sheet you want to move or copy contains the name XXX, which already exists on the destination worksheet.” David Miller (dlmille)  It was one of those days… I wa…
The viewer will learn how to use the =DISCRINV command to create a discrete random variable, use this command to model a set of probabilities and outcomes in a Monte Carlo simulation, and learn how to find the standard deviation of a set of probabil…
This Micro Tutorial will demonstrate in Google Sheets how to use the HYPERLINK function to create live links inside your spreadsheet.

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now