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

If A1 0 AND SUM(B1:L1) = 0 then A13 = Jan
If B1 0 AND SUM(C1:L1) = 0 then A13 = Feb
If D1 0 AND SUM(E1:L1) = 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(B1:L1)=0
Month = "Jan"

etc....

help is much appreciated - thanks


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,441
Default Function Creation

Teresa,

If you want Jan, Feb, Mar, Apr, etc, then Array enter, using
Ctrl-Shift-Enter, this formula in cell A13:

=TEXT(DATE(1,MAX((A1:L10)*(COLUMN(A1:L1))),1),"mm m")

or if you want January, February, March, etc. then Array enter (again,
using Ctrl-Shift-Enter)

=TEXT(DATE(1,MAX((A1:K10)*(COLUMN(A1:K1))),1),"mm mm")

Also, it is a bad idea to write functions that have the same name as Excel
functions. (MONTH is a valid Excel function)

HTH,
Bernie
MS Excel MVP


"teresa" wrote in message
...
If A1 0 AND SUM(B1:L1) = 0 then A13 = Jan
If B1 0 AND SUM(C1:L1) = 0 then A13 = Feb
If D1 0 AND SUM(E1:L1) = 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(B1:L1)=0
Month = "Jan"

etc....

help is much appreciated - thanks




  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,441
Default Function Creation

Sorry, the second formula should have also had L1 where it currently has K1.

HTH,
Bernie
MS Excel MVP


"Bernie Deitrick" <deitbe @ consumer dot org wrote in message
...
Teresa,

If you want Jan, Feb, Mar, Apr, etc, then Array enter, using
Ctrl-Shift-Enter, this formula in cell A13:

=TEXT(DATE(1,MAX((A1:L10)*(COLUMN(A1:L1))),1),"mm m")

or if you want January, February, March, etc. then Array enter (again,
using Ctrl-Shift-Enter)

=TEXT(DATE(1,MAX((A1:K10)*(COLUMN(A1:K1))),1),"mm mm")

Also, it is a bad idea to write functions that have the same name as Excel
functions. (MONTH is a valid Excel function)

HTH,
Bernie
MS Excel MVP


"teresa" wrote in message
...
If A1 0 AND SUM(B1:L1) = 0 then A13 = Jan
If B1 0 AND SUM(C1:L1) = 0 then A13 = Feb
If D1 0 AND SUM(E1:L1) = 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(B1:L1)=0
Month = "Jan"

etc....

help is much appreciated - thanks






  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Function Creation

Assumes M1 will be empty:

Dim rng as Range, cell as Range, rng1 as Range
Dim i as Long, sMonth as String
set rng = Range("A1:L1")
for each cell in rng
set rng1 = Range(cell.offset(0,1), range("M1"))
if cell.Value 0 and application.sum(rng1) = 0 then
i = cell.Column
end if
Next
sMonth = format(DateSerial(year(date),i,1),"mmm")

if you want full month names, then change mmm to mmmm

If you know there will be no zero values in months before the current month
you can simplify to:

Dim rng as Range, cell as Range
Dim i as Long, sMonth as String
set rng = Range("A1:L1")
for each cell in rng
if cell.Value 0 then
i = cell.Column
else
exit for
end if
Next
sMonth = format(DateSerial(year(date),i,1),"mmm")

--
Regards,
Tom Ogilvy



"teresa" wrote in message
...
If A1 0 AND SUM(B1:L1) = 0 then A13 = Jan
If B1 0 AND SUM(C1:L1) = 0 then A13 = Feb
If D1 0 AND SUM(E1:L1) = 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(B1:L1)=0
Month = "Jan"

etc....

help is much appreciated - thanks




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

Thanks a lot Tom - thats excellent

"Tom Ogilvy" wrote:

Assumes M1 will be empty:

Dim rng as Range, cell as Range, rng1 as Range
Dim i as Long, sMonth as String
set rng = Range("A1:L1")
for each cell in rng
set rng1 = Range(cell.offset(0,1), range("M1"))
if cell.Value 0 and application.sum(rng1) = 0 then
i = cell.Column
end if
Next
sMonth = format(DateSerial(year(date),i,1),"mmm")

if you want full month names, then change mmm to mmmm

If you know there will be no zero values in months before the current month
you can simplify to:

Dim rng as Range, cell as Range
Dim i as Long, sMonth as String
set rng = Range("A1:L1")
for each cell in rng
if cell.Value 0 then
i = cell.Column
else
exit for
end if
Next
sMonth = format(DateSerial(year(date),i,1),"mmm")

--
Regards,
Tom Ogilvy



"teresa" wrote in message
...
If A1 0 AND SUM(B1:L1) = 0 then A13 = Jan
If B1 0 AND SUM(C1:L1) = 0 then A13 = Feb
If D1 0 AND SUM(E1:L1) = 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(B1:L1)=0
Month = "Jan"

etc....

help is much appreciated - thanks







  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Function Creation

I see you had an earlier posting of this and responded positively to a
worksheet function solution. Since you posted in programming the indication
would be code as the desired solution and your example showed a code
solution. If that isn't what you wanted, it would be better to indicate
what you want - code, worksheet function or that you are interesed in both.

Might help people to avoid wasting their time.

--
Thanks,
Tom Ogilvy

"Tom Ogilvy" wrote in message
...
Assumes M1 will be empty:

Dim rng as Range, cell as Range, rng1 as Range
Dim i as Long, sMonth as String
set rng = Range("A1:L1")
for each cell in rng
set rng1 = Range(cell.offset(0,1), range("M1"))
if cell.Value 0 and application.sum(rng1) = 0 then
i = cell.Column
end if
Next
sMonth = format(DateSerial(year(date),i,1),"mmm")

if you want full month names, then change mmm to mmmm

If you know there will be no zero values in months before the current

month
you can simplify to:

Dim rng as Range, cell as Range
Dim i as Long, sMonth as String
set rng = Range("A1:L1")
for each cell in rng
if cell.Value 0 then
i = cell.Column
else
exit for
end if
Next
sMonth = format(DateSerial(year(date),i,1),"mmm")

--
Regards,
Tom Ogilvy



"teresa" wrote in message
...
If A1 0 AND SUM(B1:L1) = 0 then A13 = Jan
If B1 0 AND SUM(C1:L1) = 0 then A13 = Feb
If D1 0 AND SUM(E1:L1) = 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(B1:L1)=0
Month = "Jan"

etc....

help is much appreciated - thanks






  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 169
Default Function Creation

Tom - understood, going forward I'll bear this in mind and apologies for any
time wasting

"Tom Ogilvy" wrote:

I see you had an earlier posting of this and responded positively to a
worksheet function solution. Since you posted in programming the indication
would be code as the desired solution and your example showed a code
solution. If that isn't what you wanted, it would be better to indicate
what you want - code, worksheet function or that you are interesed in both.

Might help people to avoid wasting their time.

--
Thanks,
Tom Ogilvy

"Tom Ogilvy" wrote in message
...
Assumes M1 will be empty:

Dim rng as Range, cell as Range, rng1 as Range
Dim i as Long, sMonth as String
set rng = Range("A1:L1")
for each cell in rng
set rng1 = Range(cell.offset(0,1), range("M1"))
if cell.Value 0 and application.sum(rng1) = 0 then
i = cell.Column
end if
Next
sMonth = format(DateSerial(year(date),i,1),"mmm")

if you want full month names, then change mmm to mmmm

If you know there will be no zero values in months before the current

month
you can simplify to:

Dim rng as Range, cell as Range
Dim i as Long, sMonth as String
set rng = Range("A1:L1")
for each cell in rng
if cell.Value 0 then
i = cell.Column
else
exit for
end if
Next
sMonth = format(DateSerial(year(date),i,1),"mmm")

--
Regards,
Tom Ogilvy



"teresa" wrote in message
...
If A1 0 AND SUM(B1:L1) = 0 then A13 = Jan
If B1 0 AND SUM(C1:L1) = 0 then A13 = Feb
If D1 0 AND SUM(E1:L1) = 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(B1:L1)=0
Month = "Jan"

etc....

help is much appreciated - thanks







  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 169
Default Function Creation

Tom - understood, going forward I'll bear this in mind and apologies for any
time wasting


"Tom Ogilvy" wrote:

I see you had an earlier posting of this and responded positively to a
worksheet function solution. Since you posted in programming the indication
would be code as the desired solution and your example showed a code
solution. If that isn't what you wanted, it would be better to indicate
what you want - code, worksheet function or that you are interesed in both.

Might help people to avoid wasting their time.

--
Thanks,
Tom Ogilvy

"Tom Ogilvy" wrote in message
...
Assumes M1 will be empty:

Dim rng as Range, cell as Range, rng1 as Range
Dim i as Long, sMonth as String
set rng = Range("A1:L1")
for each cell in rng
set rng1 = Range(cell.offset(0,1), range("M1"))
if cell.Value 0 and application.sum(rng1) = 0 then
i = cell.Column
end if
Next
sMonth = format(DateSerial(year(date),i,1),"mmm")

if you want full month names, then change mmm to mmmm

If you know there will be no zero values in months before the current

month
you can simplify to:

Dim rng as Range, cell as Range
Dim i as Long, sMonth as String
set rng = Range("A1:L1")
for each cell in rng
if cell.Value 0 then
i = cell.Column
else
exit for
end if
Next
sMonth = format(DateSerial(year(date),i,1),"mmm")

--
Regards,
Tom Ogilvy



"teresa" wrote in message
...
If A1 0 AND SUM(B1:L1) = 0 then A13 = Jan
If B1 0 AND SUM(C1:L1) = 0 then A13 = Feb
If D1 0 AND SUM(E1:L1) = 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(B1:L1)=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
Shortcut Key Creation vlhogg5 Excel Discussion (Misc queries) 2 February 12th 09 12:14 AM
Spreadsheet Function creation? jkuhne Excel Worksheet Functions 1 November 21st 07 03:13 PM
Syntax for Info or Cell function for xl. file creation date driller Excel Worksheet Functions 5 January 29th 07 07:51 PM
Function Library Creation AndyF[_2_] Excel Programming 0 December 30th 03 06:59 PM
Matrix Multiplication Function creation Gabriel[_3_] Excel Programming 1 December 16th 03 04:39 PM


All times are GMT +1. The time now is 09:15 PM.

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

About Us

"It's about Microsoft Excel"