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 create User Defined function in Excel

Hi

Is there any way to create UDF in Excel?

All I want is to have a function to retrieve the sales
amount from ODBC source. The following is an example.

From Date To date Amount
01/10/2003 31/01/2003 calSales(A2,B2)


calSales is an User Defined Function. It will return the
total sales amount between dates that entered at cell A2
and B2.

Thanks
Johnny Ko
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 79
Default How to create User Defined function in Excel

you should go to visual basic editor, add a module to your spreadsheet, and
then write the function:

Public Function calSales (FromDate as date, ToDate as date) as Double

calSales=....
end function

then use it in excel like a regular function, just type in a cell
=calSales(a2, b2)

Best -
RADO


"Johnny Ko" wrote in message
...
Hi

Is there any way to create UDF in Excel?

All I want is to have a function to retrieve the sales
amount from ODBC source. The following is an example.

From Date To date Amount
01/10/2003 31/01/2003 calSales(A2,B2)


calSales is an User Defined Function. It will return the
total sales amount between dates that entered at cell A2
and B2.

Thanks
Johnny Ko



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 62
Default How to create User Defined function in Excel

Hi Johnny,
How to create UDF in Excel is not so difficult.(I think ODBC would be
difficult.)
Open VBE(Visual Basic Editor), insert a standard module, and write code
there.


Function calSales(ByVal Target1 As Range, ByVal Target2 As Range) As Double
'? Change variable type this function to suit.
'Declare variables at here.

'place your ODBC code here....This is just a sample, so it doesn't
work.
Set cn = CreateObject("ADODB.Connection")
objCnnection.ConnectionString =
"ODBC;DSN=xxx;UID=Uset-ID;PWD=Password;DBQ=xxx;ASY=OFF;"
objCnnection.Open
select_sql = ""
select_sql = assy_sql + "SELECT -----" & Chr(13) & "" & Chr(10)
select_sql = assy_sql + "FROM ------" & Chr(13) & "" & Chr(10)
select_sql = assy_sql + "WHERE -----" & Chr(13) & "" & Chr(10)
Set rs = CreateObject("ADODB.Recordset")
objRecordset.Open select_sql, cn, 0
objRecordset.Close
objCnnection.Close
Set objCnnection = Nothing
Set objCnnection = Nothing

'set Return Value
calSales = xxx
End Function


--
Kind Regards
Colo
/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/
Colo of 'The Road of The Cell Masters' :)

URL:http://www.interq.or.jp/sun/puremis/...astersLink.htm


/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/
"Johnny Ko" wrote in message
...
Hi

Is there any way to create UDF in Excel?

All I want is to have a function to retrieve the sales
amount from ODBC source. The following is an example.

From Date To date Amount
01/10/2003 31/01/2003 calSales(A2,B2)


calSales is an User Defined Function. It will return the
total sales amount between dates that entered at cell A2
and B2.

Thanks
Johnny Ko


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
User Defined Function is not working for me in Excel 2007 Abdi Excel Discussion (Misc queries) 1 November 18th 08 10:50 PM
How do i create a user defined chart in Powerpoint or excel? Magnus Charts and Charting in Excel 1 December 7th 05 04:52 PM
How can I create a user defined function in excel? Martinj Excel Discussion (Misc queries) 4 August 20th 05 06:11 PM
How to create User Defined Function Warwick Renshaw Excel Programming 0 July 25th 03 07:15 AM
Create help for user-defined function Tom Ogilvy Excel Programming 0 July 12th 03 06:11 PM


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