PC Review


Reply
Thread Tools Rate Thread

Create VBA function (UDF) in Excel 2003

 
 
Hershmab
Guest
Posts: n/a
 
      30th Nov 2009
How do I code a function
CellVal(rownum, colnum [, sheetname])
that will be the equivalent of the worksheet formula:
INDIRECT(ADDRESS(rownum, colnum [, sheetname]))
that will return the value of the specified single cell?

My knowledge of VBA is not good enough for me to find how to specify a
single-cell RANGE by its co-ordinates.
 
Reply With Quote
 
 
 
 
Jacob Skaria
Guest
Posts: n/a
 
      30th Nov 2009
Try the below. Sheetname is optional..

Function CellVal(lngRow As Long, lngColumn As Long, _
Optional strSheet As String) As Variant
If strSheet = vbNullString Then strSheet = Application.Caller.Worksheet.Name
CellVal = Sheets(strSheet).Cells(lngRow, lngColumn).Value
End Function

If this post helps click Yes
---------------
Jacob Skaria


"Hershmab" wrote:

> How do I code a function
> CellVal(rownum, colnum [, sheetname])
> that will be the equivalent of the worksheet formula:
> INDIRECT(ADDRESS(rownum, colnum [, sheetname]))
> that will return the value of the specified single cell?
>
> My knowledge of VBA is not good enough for me to find how to specify a
> single-cell RANGE by its co-ordinates.

 
Reply With Quote
 
Charles Williams
Guest
Posts: n/a
 
      30th Nov 2009
Needs to be Volatile

Function CellVal(lngRow As Long, lngColumn As Long, _
Optional strSheet As String) As Variant

Application.Volatile
on Error GoTo Fail:
If strSheet = vbNullString Then strSheet = Application.Caller.Parent.Name
CellVal = Sheets(strSheet).Cells(lngRow, lngColumn).Value
exit function
Fail:
CellVal=cverr(xlerrna)
End Function

Charles
___________________________________
The Excel Calculation Site
http://www.decisionmodels.com

"Jacob Skaria" <(E-Mail Removed)> wrote in message
news:CEF460D1-C2FC-440D-8EB3-(E-Mail Removed)...
> Try the below. Sheetname is optional..
>
> Function CellVal(lngRow As Long, lngColumn As Long, _
> Optional strSheet As String) As Variant
> If strSheet = vbNullString Then strSheet =
> Application.Caller.Worksheet.Name
> CellVal = Sheets(strSheet).Cells(lngRow, lngColumn).Value
> End Function
>
> If this post helps click Yes
> ---------------
> Jacob Skaria
>
>
> "Hershmab" wrote:
>
>> How do I code a function
>> CellVal(rownum, colnum [, sheetname])
>> that will be the equivalent of the worksheet formula:
>> INDIRECT(ADDRESS(rownum, colnum [, sheetname]))
>> that will return the value of the specified single cell?
>>
>> My knowledge of VBA is not good enough for me to find how to specify a
>> single-cell RANGE by its co-ordinates.

>



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Create VBA Function/Sub programatically within Excel VBA =?Utf-8?B?cmFlbF9sdWNpZA==?= Microsoft Excel Programming 2 28th Sep 2007 08:51 AM
Re: Create Function using Excel VBA Dave Peterson Microsoft Excel Programming 3 4th Jan 2007 09:25 PM
Excel 2003, Insert Function, create full name & descriptions =?Utf-8?B?Y3liZXJzdXJmZXI=?= Microsoft Excel Worksheet Functions 0 14th Jul 2005 05:13 PM
create a discount function in excel number Microsoft Excel Programming 5 7th Jul 2005 08:13 PM
Can I create a function in Excel? =?Utf-8?B?Sm9zZQ==?= Microsoft Excel Misc 1 22nd Jul 2004 07:36 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 05:35 AM.