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
|