Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,069
Default UDF setup for a range of cells

I would like to create a user function that performs a series of calculations
on a range of cells that the user selects. I know this is probablly fairly
easy, but how do I designate the range of cells in VBA and perform my calcs
on that range?
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default UDF setup for a range of cells

Your UDF should accept as parameters the range on which it is to
operate. This will ensure that it will be recalculated with a
relevant cell is changed.It is very poor programming practice to
hard code cell references within a UDF. E.g.,

Public Function MyUDF(InputRange As Range) As Variant
' do your work on InputRange
MyUDF = some_result
End Function

Then you can call this from the worksheet with a formula like

=MyUDF(A1:A10)


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com




"John" wrote in message
...
I would like to create a user function that performs a series of
calculations
on a range of cells that the user selects. I know this is
probablly fairly
easy, but how do I designate the range of cells in VBA and
perform my calcs
on that range?



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,069
Default UDF setup for a range of cells

Thanks for the help and quick response Chip... I will start and be off an
running I hope.

"Chip Pearson" wrote:

Your UDF should accept as parameters the range on which it is to
operate. This will ensure that it will be recalculated with a
relevant cell is changed.It is very poor programming practice to
hard code cell references within a UDF. E.g.,

Public Function MyUDF(InputRange As Range) As Variant
' do your work on InputRange
MyUDF = some_result
End Function

Then you can call this from the worksheet with a formula like

=MyUDF(A1:A10)


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com




"John" wrote in message
...
I would like to create a user function that performs a series of
calculations
on a range of cells that the user selects. I know this is
probablly fairly
easy, but how do I designate the range of cells in VBA and
perform my calcs
on that range?




  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,058
Default UDF setup for a range of cells

Here is a simple summer:


Function summer(r As Range) As Double
Dim rr As Range
For Each rr In r
summer = summer + rr.Value
Next
End Function

In the worksheet, use it like:
=summer(A1:C3)
--
Gary''s Student


"John" wrote:

I would like to create a user function that performs a series of calculations
on a range of cells that the user selects. I know this is probablly fairly
easy, but how do I designate the range of cells in VBA and perform my calcs
on that range?

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,069
Default UDF setup for a range of cells

thanks, all tips are appreciated :)

"Gary''s Student" wrote:

Here is a simple summer:


Function summer(r As Range) As Double
Dim rr As Range
For Each rr In r
summer = summer + rr.Value
Next
End Function

In the worksheet, use it like:
=summer(A1:C3)
--
Gary''s Student


"John" wrote:

I would like to create a user function that performs a series of calculations
on a range of cells that the user selects. I know this is probablly fairly
easy, but how do I designate the range of cells in VBA and perform my calcs
on that range?

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
Dynamic Range Setup... Trevor Williams[_2_] Excel Worksheet Functions 8 July 29th 09 04:05 PM
Print Range Setup MCheru Setting up and Configuration of Excel 2 March 27th 09 03:10 AM
Print Range Setup MCheru Excel Worksheet Functions 6 February 25th 09 09:56 AM
how do I setup a formula for a same range of cells on 12 sheets Vikram Mohan Excel Worksheet Functions 0 January 11th 06 10:46 AM
Print range setup Patty via OfficeKB.com Excel Discussion (Misc queries) 2 October 14th 05 07:06 PM


All times are GMT +1. The time now is 02:29 AM.

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"