|Just a posting tip...|
Since we can't see your spreadsheet from where we're sitting, statements such as "but it doesn't work" are often not very useful.
Sometimes we can spot on obvious error in the use of the function. but most times it would better if you explained what "but it doesn't work" means.
Does it return the wrong value, does it return an error, etc.
I hope that Milind was able to solve your issue, but if not, please provide some details as to what "but it doesn't work" means.
Click Here Before Posting Data or VBA Code ---> How To Post Data or Code.