Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 5
Default how to use the function written in VBA in excel sheet

Hi, dear all

i wrote a small function in VBA and want to use it in excel sheet. the
script is like,


Function sample(sheetname As Integer) As Integer

Dim R As Excel.Range
Dim c As Variant

sample = 0
For Each c In Worksheets(sheetname).Range("A1").CurrentRegion
If Right(c.Value, 1) = "*" Then
sample = 1
Exit Function
End If
Next

End Function

But when i type the formular in excel sheet, it can not work. the
version i use is Excel 2000.
My problem is how can i use this function in excel sheet???

Thank you

  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 11,058
Default how to use the function written in VBA in excel sheet

Hi Kelly:


User Defined Functions (UDFs) are very easy to install and use:

1. ALT-F11 brings up the VBE window
2. ALT-I
ALT-M opens a fresh module
3. paste the stuff in and close the VBE window

If you save the workbook, the UDF will be saved with it.

To remove the UDF:

1. bring up the VBE window as above
2. clear the code out
3. close the VBE window

To use the UDF from Excel:

=sample(A1)

To learn more about macros in general, see:

http://www.mvps.org/dmcritchie/excel/getstarted.htm

or

http://www.cpearson.com/excel/Writin...ionsInVBA.aspx
for specifics on UDFs




--
Gary''s Student - gsnu2007a


"kelly" wrote:

Hi, dear all

i wrote a small function in VBA and want to use it in excel sheet. the
script is like,


Function sample(sheetname As Integer) As Integer

Dim R As Excel.Range
Dim c As Variant

sample = 0
For Each c In Worksheets(sheetname).Range("A1").CurrentRegion
If Right(c.Value, 1) = "*" Then
sample = 1
Exit Function
End If
Next

End Function

But when i type the formular in excel sheet, it can not work. the
version i use is Excel 2000.
My problem is how can i use this function in excel sheet???

Thank you


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 to use the function written in VBA in excel sheet kelly Excel Discussion (Misc queries) 0 October 30th 07 08:24 AM
Need Excel function to convert dollars to written words Joanne Excel Discussion (Misc queries) 2 November 9th 06 05:52 PM
Is there a macro or function to convert values to it written text Dang Tran Excel Worksheet Functions 1 April 19th 06 11:17 PM
function to convert whole numbers to written text Mani K Excel Worksheet Functions 2 December 29th 05 09:24 AM
Excel is written in which programming language ? Shrikant Excel Discussion (Misc queries) 1 September 1st 05 10:58 AM


All times are GMT +1. The time now is 07:06 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"