Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 169
Default Creating a Function

If A1 0 AND SUM(A2:A12) = 0 then A13 = Jan
If A2 0 AND SUM(A3:A12) = 0 then A13 = Feb
If A3 0 AND SUM(A4:A12) = 0 then A13 = March
etc.etc.

Rather than just using nested Ifs which is cumbersome I am trying:

Function Month(Integer)

Select Case Integer
Case a10,sum(a2:a12)=0
Month = "Jan"

etc....

help is much appreciated - thanks



  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 12
Default Creating a Function

try
Function mmm(rng As Range) As String
Dim numAry, monthAry, i As Long
numAry = Array(1, 2, 3): monthAry = Array("Jan", "Feb", "Mar")
For i = LBound(numAry) To UBound(numAry)
If rng(numAry(i), 1) < "" And _
Application.Sum(rng.Resize(rng.Rows.Count -
numAry(i)).Offset(numAry(i))) = 0 Then
mmm = monthAry(i): Exit For
End If
Next
Erase numAry, monthAry
End Function

use like

=mmm(A1:A12)

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 169
Default Creating a Function

Thanks for this but cant get it to work exactly


"Seiya" wrote:

try
Function mmm(rng As Range) As String
Dim numAry, monthAry, i As Long
numAry = Array(1, 2, 3): monthAry = Array("Jan", "Feb", "Mar")
For i = LBound(numAry) To UBound(numAry)
If rng(numAry(i), 1) < "" And _
Application.Sum(rng.Resize(rng.Rows.Count -
numAry(i)).Offset(numAry(i))) = 0 Then
mmm = monthAry(i): Exit For
End If
Next
Erase numAry, monthAry
End Function

use like

=mmm(A1:A12)


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 292
Default Creating a Function

Hi

Try this little thing in A13:

=TEXT(DATE(1,SUMPRODUCT(MAX(ROW(A1:A12)*(A1:A120) )),1),"MMM")

HTH. Best wishes Harald

"teresa" skrev i melding
...
If A1 0 AND SUM(A2:A12) = 0 then A13 = Jan
If A2 0 AND SUM(A3:A12) = 0 then A13 = Feb
If A3 0 AND SUM(A4:A12) = 0 then A13 = March
etc.etc.

Rather than just using nested Ifs which is cumbersome I am trying:

Function Month(Integer)

Select Case Integer
Case a10,sum(a2:a12)=0
Month = "Jan"

etc....

help is much appreciated - thanks





  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 169
Default Creating a Function

Harald - thats perfect
can you explain to me what the function below does - very grateful,
I understand each individual function but not working together

SUMPRODUCT(MAX(ROW(A1:A12)*(A1:A120)))

"Harald Staff" wrote:

Hi

Try this little thing in A13:

=TEXT(DATE(1,SUMPRODUCT(MAX(ROW(A1:A12)*(A1:A120) )),1),"MMM")

HTH. Best wishes Harald

"teresa" skrev i melding
...
If A1 0 AND SUM(A2:A12) = 0 then A13 = Jan
If A2 0 AND SUM(A3:A12) = 0 then A13 = Feb
If A3 0 AND SUM(A4:A12) = 0 then A13 = March
etc.etc.

Rather than just using nested Ifs which is cumbersome I am trying:

Function Month(Integer)

Select Case Integer
Case a10,sum(a2:a12)=0
Month = "Jan"

etc....

help is much appreciated - thanks








  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 292
Default Creating a Function

Hi

An array formula like that is like a package of individual formulas. These
formulas are
Row(A1)*(A10) ' returns 1 if A10, else 0
Row(A2)*(A20) ' returns 2 if A30, else 0
Row(A3)*(A30) 'and so on
Row(A4)*(A40)
....
MAX searches the highest of these results, and SUMPRODUCT wraps it up as an
array formula.

Then we use this result as month number in a date, and we convert that date
to text monthname. I guess you found out already, so just for the
archive....

Best wishes Harald

"teresa" skrev i melding
...
Harald - thats perfect
can you explain to me what the function below does - very grateful,
I understand each individual function but not working together

SUMPRODUCT(MAX(ROW(A1:A12)*(A1:A120)))

"Harald Staff" wrote:

Hi

Try this little thing in A13:

=TEXT(DATE(1,SUMPRODUCT(MAX(ROW(A1:A12)*(A1:A120) )),1),"MMM")

HTH. Best wishes Harald

"teresa" skrev i melding
...
If A1 0 AND SUM(A2:A12) = 0 then A13 = Jan
If A2 0 AND SUM(A3:A12) = 0 then A13 = Feb
If A3 0 AND SUM(A4:A12) = 0 then A13 = March
etc.etc.

Rather than just using nested Ifs which is cumbersome I am trying:

Function Month(Integer)

Select Case Integer
Case a10,sum(a2:a12)=0
Month = "Jan"

etc....

help is much appreciated - thanks








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
Creating a Function Stu Gnu[_2_] Excel Worksheet Functions 4 August 31st 07 08:44 AM
Need help creating a function nander Excel Discussion (Misc queries) 3 February 20th 06 04:57 AM
Creating a Function yanf7[_2_] Excel Programming 5 September 3rd 04 03:17 PM
Creating a Sub Function No Name Excel Programming 2 May 18th 04 08:46 PM
Creating a function Todd Huttenstine[_2_] Excel Programming 15 December 5th 03 11:38 PM


All times are GMT +1. The time now is 12:51 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"