+ Reply to Thread
Results 1 to 4 of 4

How to access cell values in VBA Function using Range parameter

  1. #1
    Registered User
    Join Date
    04-27-2009
    Location
    Bristow, VA
    MS-Off Ver
    Excel 2007
    Posts
    15

    How to access cell values in VBA Function using Range parameter

    Newbie question:
    I am writing a VBA function to work on a range of cells (the first time I'm passing a parameter of type Range). I can't figure out the proper syntax to get the values of the cells in that range. The code looks like:

    Please Login or Register  to view this content.
    ...

    I have used the Watch window to show the contents of c and c.Value2. Under c, I see Value2 = 5.02e-04 (the value I want to retrieve), but c.Value2 is shown as Empty and SwimTime = 0. How can I retrieve the values of the cells in the Times range within the function?
    Thanks,
    Steve
    Last edited by jeffreybrown; 07-04-2012 at 08:40 AM.

  2. #2
    Valued Forum Contributor Steffen Thomsen's Avatar
    Join Date
    10-15-2010
    Location
    Kolding, Denmark
    MS-Off Ver
    Excel 2007 and Excel 2010
    Posts
    953

    Re: How to access cell values in VBA Function using Range parameter

    May i ask what the goal of the function is?

    Do you need to get back an array of values or a single value?
    Is the range input a single column range or a multi column range?
    Please take time to read the forum rules

  3. #3
    Registered User
    Join Date
    04-27-2009
    Location
    Bristow, VA
    MS-Off Ver
    Excel 2007
    Posts
    15

    Re: How to access cell values in VBA Function using Range parameter

    The goal of the function is to reduce a set of swimmer's times (1 to 7 values) to a single value. The other argument to the function is the algorithm to use (pick latest, pick the fastest, average or weighted average).

  4. #4
    Registered User
    Join Date
    04-27-2009
    Location
    Bristow, VA
    MS-Off Ver
    Excel 2007
    Posts
    15

    Re: How to access cell values in VBA Function using Range parameter

    Apparently c.Value2 was correct. I had put a breakpoint in the macro and when tracing it I got the "Empty" and 0 results in the original note. When I removed the breakpoint, it ran correctly. I'm guessing that Excel called the function multiple times. The first call, the inputs were not all complete (they come from other worksheet functions). I'm guessing that eventually all the inputs get calculated and the function is executed again ... at which time it returns the data I expected. I'm not sure why the c Watch showed the proper value and the c.Value2 Watch showed a different value though.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1