Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5
Default Call VBA function from cell

Is it possible to call a VBA function from a cell on a worksheet?

For example:
- Cell A1 contains a date.
- I want Cell A2 to evaluate the date in A1 and then display the date
corresponding to the end of that financial quarter.
- So if A1 = February 23, 2005, I want A2 to return March 31, 2005.

I can write a Function in VBA that would return this value, I just don't
know how I would call it from within a cell on an Excel worksheet and pass
the value of A1.

Any help is appreciated.

Cheers,
Don
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 226
Default Call VBA function from cell

You need to set it up something like this:

In a VBA module you have your function:

Function GetQuarterEnd (RngDate as range) as Date
'Code to convert RngDate.Value to last day of Quarter
'the code should assign the last day of quarter to GetQuarterEnd e.g
GetQuarterEnd = myDateVariable
End Function

Then in A2 (formatted as date) you enter the formula =GetQuarterEnd(A1)

HTH
Rowan


"donesquire" wrote:

Is it possible to call a VBA function from a cell on a worksheet?

For example:
- Cell A1 contains a date.
- I want Cell A2 to evaluate the date in A1 and then display the date
corresponding to the end of that financial quarter.
- So if A1 = February 23, 2005, I want A2 to return March 31, 2005.

I can write a Function in VBA that would return this value, I just don't
know how I would call it from within a cell on an Excel worksheet and pass
the value of A1.

Any help is appreciated.

Cheers,
Don

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5
Default Call VBA function from cell

Mmmm, I'm afraid this isn't working. When I enter the function name and
reference cell A1, I get the #NAME? error. Any thoughts?


"Rowan" wrote:

You need to set it up something like this:

In a VBA module you have your function:

Function GetQuarterEnd (RngDate as range) as Date
'Code to convert RngDate.Value to last day of Quarter
'the code should assign the last day of quarter to GetQuarterEnd e.g
GetQuarterEnd = myDateVariable
End Function

Then in A2 (formatted as date) you enter the formula =GetQuarterEnd(A1)

HTH
Rowan


"donesquire" wrote:

Is it possible to call a VBA function from a cell on a worksheet?

For example:
- Cell A1 contains a date.
- I want Cell A2 to evaluate the date in A1 and then display the date
corresponding to the end of that financial quarter.
- So if A1 = February 23, 2005, I want A2 to return March 31, 2005.

I can write a Function in VBA that would return this value, I just don't
know how I would call it from within a cell on an Excel worksheet and pass
the value of A1.

Any help is appreciated.

Cheers,
Don

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5
Default Call VBA function from cell

My mistake. I placed the code into "This Workbook" instead of into a Module.

Your sample code worked perfectly. Many thanks!


"donesquire" wrote:

Mmmm, I'm afraid this isn't working. When I enter the function name and
reference cell A1, I get the #NAME? error. Any thoughts?


"Rowan" wrote:

You need to set it up something like this:

In a VBA module you have your function:

Function GetQuarterEnd (RngDate as range) as Date
'Code to convert RngDate.Value to last day of Quarter
'the code should assign the last day of quarter to GetQuarterEnd e.g
GetQuarterEnd = myDateVariable
End Function

Then in A2 (formatted as date) you enter the formula =GetQuarterEnd(A1)

HTH
Rowan


"donesquire" wrote:

Is it possible to call a VBA function from a cell on a worksheet?

For example:
- Cell A1 contains a date.
- I want Cell A2 to evaluate the date in A1 and then display the date
corresponding to the end of that financial quarter.
- So if A1 = February 23, 2005, I want A2 to return March 31, 2005.

I can write a Function in VBA that would return this value, I just don't
know how I would call it from within a cell on an Excel worksheet and pass
the value of A1.

Any help is appreciated.

Cheers,
Don

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 226
Default Call VBA function from cell

You're welcome.

"donesquire" wrote:

My mistake. I placed the code into "This Workbook" instead of into a Module.

Your sample code worked perfectly. Many thanks!


"donesquire" wrote:

Mmmm, I'm afraid this isn't working. When I enter the function name and
reference cell A1, I get the #NAME? error. Any thoughts?


"Rowan" wrote:

You need to set it up something like this:

In a VBA module you have your function:

Function GetQuarterEnd (RngDate as range) as Date
'Code to convert RngDate.Value to last day of Quarter
'the code should assign the last day of quarter to GetQuarterEnd e.g
GetQuarterEnd = myDateVariable
End Function

Then in A2 (formatted as date) you enter the formula =GetQuarterEnd(A1)

HTH
Rowan


"donesquire" wrote:

Is it possible to call a VBA function from a cell on a worksheet?

For example:
- Cell A1 contains a date.
- I want Cell A2 to evaluate the date in A1 and then display the date
corresponding to the end of that financial quarter.
- So if A1 = February 23, 2005, I want A2 to return March 31, 2005.

I can write a Function in VBA that would return this value, I just don't
know how I would call it from within a cell on an Excel worksheet and pass
the value of A1.

Any help is appreciated.

Cheers,
Don

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
Use reference text from one cell in another function call Randy Excel Worksheet Functions 3 March 10th 08 05:31 PM
How do i call a function to a cell? Bill Excel Worksheet Functions 3 February 17th 07 12:54 AM
call a vb function from a cell mike grasso Excel Programming 3 July 9th 04 01:51 PM
How do I call a VBA function from a cell? Scott Lyon Excel Programming 1 October 14th 03 06:55 PM
Write a function call into an Excel cell from VBA Conceptor Excel Programming 2 September 10th 03 05:41 PM


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