Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7
Default UDF to set cell number style

Hi all,
if I enter =TODAY() into a cell, its format changes into Date. How could my
own UDF do the same?

I've tried
Public Function YESTERDAY() As Date
YESTERDAY = DateAdd("d", -1, Now)
Application.ThisCell.NumberFormat = "m/d/yyyy"
End Function

But setting the NumberFormat property inside UDF has no effect.
Any way here?

Thanks,
Jan

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default UDF to set cell number style


Can't. A UDF can't do anything except return a value to the cell(s) in
which the function appears. There are some obscure exceptions, but this
isn't one of them.


--
shg
------------------------------------------------------------------------
shg's Profile: http://www.thecodecage.com/forumz/member.php?userid=13
View this thread: http://www.thecodecage.com/forumz/sh...ad.php?t=24593

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,934
Default UDF to set cell number style

'shg' has answered your question, but I just wanted to point out you can
simplify your function as follows...

Public Function YESTERDAY() As Date
YESTERDAY = Date - 1
End Function

This is slightly different than your function in that it does not return the
time. If you wanted the time returned, just use Now instead of Date.

--
Rick (MVP - Excel)


"Jan Kučera" wrote in message
...
Hi all,
if I enter =TODAY() into a cell, its format changes into Date. How could
my own UDF do the same?

I've tried
Public Function YESTERDAY() As Date
YESTERDAY = DateAdd("d", -1, Now)
Application.ThisCell.NumberFormat = "m/d/yyyy"
End Function

But setting the NumberFormat property inside UDF has no effect.
Any way here?

Thanks,
Jan


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7
Default UDF to set cell number style

Okay, thank you shg for answering and Rick for the pointout!

Jan


"Rick Rothstein" wrote in message
...
'shg' has answered your question, but I just wanted to point out you can
simplify your function as follows...

Public Function YESTERDAY() As Date
YESTERDAY = Date - 1
End Function

This is slightly different than your function in that it does not return
the time. If you wanted the time returned, just use Now instead of Date.

--
Rick (MVP - Excel)


"Jan Kučera" wrote in message
...
Hi all,
if I enter =TODAY() into a cell, its format changes into Date. How could
my own UDF do the same?

I've tried
Public Function YESTERDAY() As Date
YESTERDAY = DateAdd("d", -1, Now)
Application.ThisCell.NumberFormat = "m/d/yyyy"
End Function

But setting the NumberFormat property inside UDF has no effect.
Any way here?

Thanks,
Jan


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
why does it only bold the number in red when i apply the % style? senorita2009 Excel Discussion (Misc queries) 2 October 5th 09 06:31 PM
How to count number of Cell have Strike Through Effect & Bold as font style. Akash Maheshwari Excel Discussion (Misc queries) 6 June 29th 07 09:39 PM
How to count number of Cell have Strike Through Effect & Bold as font style. Akash Excel Programming 10 June 28th 07 06:28 AM
Need Number style Metrazal[_40_] Excel Programming 2 March 9th 06 07:03 PM
Accounting Style Number Button Sabine Excel Worksheet Functions 3 February 2nd 05 05:25 PM


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