?
Solved

Macro and/or function that determines what week a date falls into

Posted on 2011-04-27
5
Medium Priority
?
265 Views
Last Modified: 2012-05-11
Please take a look at the attached workbook. I need something that will tell me the week for all the dates in Column BA.

Thanks,
John
FindWeek.xls
0
Comment
Question by:gabrielPennyback
  • 3
  • 2
5 Comments
 
LVL 81

Accepted Solution

by:
zorvek (Kevin Jones) earned 2000 total points
ID: 35480348
Use this formula:

=INDEX($BB$3:$DA$3,1,TRUNC((BA6-$BB$1+7)/7))

Kevin
0
 
LVL 81

Expert Comment

by:zorvek (Kevin Jones)
ID: 35480361
Place the formula in AY and copy down as far as needed. You don't need the table in the header - the only cell referenced is BB1 - the first day of the first week of the year.

Kevin
0
 
LVL 1

Author Comment

by:gabrielPennyback
ID: 35480504
Thanks, Kevin, I think that will do it. In the meantime, I figured out a macro that will do it with the table. Now I have two ways to do it. I like yours because there's no need for the table! However you can still tell me how impressed you are that I was ab;e to figure out this macro :-)

Thanks,
John


Sub FindRow()
Dim cel As Range
For Each cel In Range("BA6:BA320")
cel.Select
Dim wk As Range, x As Long
ActiveWorkbook.Names.Add Name:="ThisWeek", RefersTo:=cel.EntireRow
x = [ThisWeek].Row
cel.Offset(0, -3) = x
Set wk = [ThisWeek].Find(What:="week", After:=Cells(x, 53), LookIn:=xlValues, LookAt _
        :=xlPart, SearchOrder:=xlByColumns, SearchDirection:=xlNext)
cel.Offset(0, -1) = wk
Next cel
End Sub

Open in new window

0
 
LVL 81

Expert Comment

by:zorvek (Kevin Jones)
ID: 35480530
I'm not sure if I should be impressed or appalled! What the heck is that macro doing? Creating named ranges? Inside the loop? Dang!
0
 
LVL 1

Author Closing Comment

by:gabrielPennyback
ID: 35751451
How about impressed AND appalled!

Thanks, Kevin :-)

- John
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When you see single cell contains number and text, and you have to get any date out of it seems like cracking our heads.
How to get Spreadsheet Compare 2016 working with the 64 bit version of Office 2016
This Micro Tutorial will demonstrate on a Mac how to change the sort order for chart legend values and decrpyt the intimidating chart menu.
This Micro Tutorial will demonstrate how to use longer labels with horizontal bar charts instead of the vertical column chart.

864 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