Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default How to call Macro in UDF

Dear Excel Genius guys

i have a small query
can there be Numberformat in UDF (User Defined Function)

My VBA Code is

Function Crore (Selcell as variant)
crore=selcell/10000000
end function

now i want that at the same time its number format should also changed
& show us
"#,#00.000[$ Cr.]" 2 Cr.

now for that i have macro

sub crnumberformat()
ActiveCell.NumberFormat = "#,#00.000[$ Cr.]"
end sub

my query is how to call a macro in function

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,173
Default How to call Macro in UDF

Anand

You will need to re-think this for two reasons

1) You can only return a value from a function and this is not formatted
2) You would be calling a sub BEFORE any value was returned (even if it
would work)

You might look at doing your formatting using a Worksheet_Change event

Private Sub Worksheet_Change(ByVal Target As Range)
Application.EnableEvents=False
Target.NumberFormat = "#,#00.000[$ Cr.]"
Application.EnableEvents=True
End Sub

You would also be able to restrict this, for example to column A by the
following

Private Sub Worksheet_Change(ByVal Target As Range)
If Not Application.Intersect(Columns("A"), Target) Is Nothing Then
Application.EnableEvents = False
Target.NumberFormat = "#,#00.000[$ Cr.]"
Application.EnableEvents = True
End If
End Sub


--
HTH
Nick Hodge
Microsoft MVP - Excel
Southampton, England
DTHIS
www.nickhodge.co.uk


"Anand the Smarty" wrote in message
ups.com...
Dear Excel Genius guys

i have a small query
can there be Numberformat in UDF (User Defined Function)

My VBA Code is

Function Crore (Selcell as variant)
crore=selcell/10000000
end function

now i want that at the same time its number format should also changed
& show us
"#,#00.000[$ Cr.]" 2 Cr.

now for that i have macro

sub crnumberformat()
ActiveCell.NumberFormat = "#,#00.000[$ Cr.]"
end sub

my query is how to call a macro in function


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
How can run a macro ( call a macro) on selection of any filtercriteria? [email protected] Excel Worksheet Functions 7 February 20th 09 12:34 AM
Call an Access macro from an Excel macro Jason W Excel Discussion (Misc queries) 1 May 1st 08 08:33 PM
Excel Macro call Word Macro with Parameters Bill Sturdevant[_2_] Excel Programming 9 May 24th 07 12:21 AM
Call macro stored in Excel workbook from Outlook's macro Gvaram Excel Programming 0 October 4th 06 05:47 PM
How to call a macro in an XLA add-in Peter Laman Excel Discussion (Misc queries) 1 March 10th 05 05:40 PM


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