Eliminating Multiple IF/THEN loops

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have a table of data with dates in the top row(weekly). I need to take an
action depending on which quarter of the year the date is in. What I am
working on is assigning a number 1 thru 4 based on evaluation of the date, ie
If Month(N4)<4 Then
Qtr= 1
Else if Month (N4)>3 AND Month (N4) <7 Then
Qtr = 2......

From this I would then have something like

If Qtr = 1 then
evaulate cell

I believe there is a cleaner way to do this instead of multiple if
statements, if any could provide insight it would be appreciated.
 
You can calculate the Qtr value:

Qtr=INT((Month(N4)-1)/3)+1

Does this help?

You could then use Select CASE instead "If" statements to determine action
 
Probably a select case statement

select Month(N4)
case <= 3
Qtr = 1
case <= 6
Qtr = 2
case <= 9
Qtr = 3
case <= 12
Qtr = 4
case else
msgbox "Error"
end select
 
JC said:
I have a table of data with dates in the top row(weekly). I need to take an
action depending on which quarter of the year the date is in. What I am
working on is assigning a number 1 thru 4 based on evaluation of the date, ie
If Month(N4)<4 Then
Qtr= 1
Else if Month (N4)>3 AND Month (N4) <7 Then
Qtr = 2......

From this I would then have something like

If Qtr = 1 then
evaulate cell

I believe there is a cleaner way to do this instead of multiple if
statements, if any could provide insight it would be appreciated.
 
Another thought might be to use the format function which can format the
quarter (why this only exist on the VB side and not the Excel side is a
mystery...)

Qtr = CInt(format(N4, "q"))
 
Back
Top