Yahoo Answers is shutting down on May 4th, 2021 (Eastern Time) and beginning April 20th, 2021 (Eastern Time) the Yahoo Answers website will be in read-only mode. There will be no changes to other Yahoo properties or services, or your Yahoo account. You can find more information about the Yahoo Answers shutdown and how to download your data on this help page.

VBA programming formula needed.?

Hi there. I'm writing a program in VBA, and need a couple of functions to convert a week number into Periods and Weeks.

The data is as such:

1 to be converted into Period 1 Week 1

2 to be converted into Period 1 Week 2

3 to be converted into Period 1 Week 3

4 to be converted into Period 1 Week 4

5 to be converted into Period 2 Week 1

6 to be converted into Period 2 Week 2

7 to be converted into Period 2 Week 3

8 to be converted into Period 2 Week 4

9 to be converted into Period 3 Week 1

10 to be converted into Period 1 Week 2

....etc

So I need a PeriodConvert(Value) and a WeekConvert(Value) function,

I've done it before with some REALLY ugly formulas, just wondering if there is a nicer way of doing it.

Many thanks

Update:

Armchair Pilot....

You are wrong, I think you assumed it was as simple as I did. however, if you test it with a set of data, you'll find it doesn't work.

examples:

If "data" = 4, the result is Period 2, it should be Period 1.

Also, (sticking with 4 here), Week comes out as 0, should be 4.

Any more suggestions?

1 Answer

Relevance
  • 1 decade ago
    Favorite Answer

    The formulas are:

    Period = (data \ 4) + 1

    Week = data mod 4

    Where data = 1,2,3,4 etc

    --------------------------------------------------------------------------

    Edit: good point: try this

    Period = (data + 3) \ 4

    Week = data mod 4

    If (Week = 0) Then Week = Week + 1

Still have questions? Get your answers by asking now.