Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Eliminating Multiple IF/THEN loops

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.
--
Thanks in advance,
JC
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,339
Default Eliminating Multiple IF/THEN loops

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
on value of Qtr

"JC" wrote:

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.
--
Thanks in advance,
JC

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 486
Default Eliminating Multiple IF/THEN loops

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
--
HTH...

Jim Thomlinson


"JC" wrote:

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.
--
Thanks in advance,
JC

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 105
Default Eliminating Multiple IF/THEN loops

JC wrote:
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.

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

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

Bill
  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 486
Default Eliminating Multiple IF/THEN loops

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"))
--
HTH...

Jim Thomlinson


"Jim Thomlinson" wrote:

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
--
HTH...

Jim Thomlinson


"JC" wrote:

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.
--
Thanks in advance,
JC

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
loops???? harry buggy Excel Worksheet Functions 2 August 14th 07 06:33 PM
Rename multiple csv files eliminating (-) hyphens from the label. simplymidori[_2_] Excel Discussion (Misc queries) 2 July 26th 07 11:34 PM
Multiple test loops davegb Excel Programming 8 March 10th 05 03:31 PM
Multiple loops one result hotherps[_56_] Excel Programming 2 May 11th 04 06:09 PM
macro that loops to multiple columns Brad Zenner Excel Programming 1 July 22nd 03 03:17 AM


All times are GMT +1. The time now is 08:00 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"