+ Reply to Thread
Results 1 to 11 of 11

range and vb function

  1. #1
    Registered User
    Join Date
    01-27-2014
    Location
    kathmandu
    MS-Off Ver
    Microsoft Excel for Mac version 16.68, Office LTSC
    Posts
    33

    range and vb function

    As excel wont allow me to add hours more than 5 digit I use this public function to add two cells
    Please Login or Register  to view this content.
    Similarly if I were to select multiple cells alligned vertically then how do I create the function?

    I.e add more range?

  2. #2
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: range and vb function

    Where's the rest of the function? How do you use it? What's in the cells?
    Entia non sunt multiplicanda sine necessitate

  3. #3
    Forum Guru Izandol's Avatar
    Join Date
    03-29-2012
    Location
    *
    MS-Off Ver
    Excel 20(03|10|13)
    Posts
    2,581

    Re: range and vb function

    Quote Originally Posted by pannam View Post
    As excel wont allow me to add hours more than 5 digit
    What does this mean?
    • Please remember to mark threads Solved with Thread Tools link at top of page.
    • Please use code tags when posting code: [code]Place your code here[/code]
    • Please read Forum Rules

  4. #4
    Registered User
    Join Date
    01-27-2014
    Location
    kathmandu
    MS-Off Ver
    Microsoft Excel for Mac version 16.68, Office LTSC
    Posts
    33

    Re: range and vb function

    Quote Originally Posted by Izandol View Post
    What does this mean?
    it means i can add hhhh:mm +hhhh:mm and not get an error but if i were to add hhhhh:mm+hhhh:mm Excel will give an error.

  5. #5
    Registered User
    Join Date
    01-27-2014
    Location
    kathmandu
    MS-Off Ver
    Microsoft Excel for Mac version 16.68, Office LTSC
    Posts
    33

    Re: range and vb function

    this is the code
    Please Login or Register  to view this content.
    i can add hhhhhhh:mm (cell A1) with hhhhhh:mm (cell A2) using =st(A1,A2)
    but if i were to add multiple cells i.e A1:A9 I hit error. Hope you could guide me to properly phrase the function.

  6. #6
    Forum Guru
    Join Date
    04-13-2005
    Location
    North America
    MS-Off Ver
    2002/XP and 2007
    Posts
    15,819

    Re: range and vb function

    i can add hhhhhhh:mm (cell A1) with hhhhhh:mm (cell A2) using =st(A1,A2) but if i were to add multiple cells i.e A1:A9 I hit error.
    It might help if you could be more specific about the error you are getting. What is the error? What line/statement triggers the error?

    If I may, is there an important reason for trying to make this an array function? I have posted a few times in this forum about how to make UDF's return multiple values, but I believe that it is easiest to code a UDF so it takes one set of input values and returns a single result. Without knowing your reasons for wanting to make this an array function, I would suggest that the easiest way to "properly phrase the function" is to leave it coded as is for a single result. Then, in the spreadsheet, when you need multiple results based on different inputs in a range, you will simply copy the function (make sure references in the function call are relative) and paste into the appropriate destination cells.

    This should be no different than if you were using the built in SUM() function to add two cells together. Your first function call would be =sum(A2,C2). Then, to sum up each pair in A and C, you would simply copy this function down.
    Quote Originally Posted by shg
    Mathematics is the native language of the natural world. Just trying to become literate.

  7. #7
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: range and vb function

    Why do you need a UDF at all?

    A
    B
    C
    D
    1
    15654:27
    8782:28
    24436:55
    C1: =A1+B1

  8. #8
    Registered User
    Join Date
    01-27-2014
    Location
    kathmandu
    MS-Off Ver
    Microsoft Excel for Mac version 16.68, Office LTSC
    Posts
    33

    Re: range and vb function

    Quote Originally Posted by shg View Post
    Why do you need a UDF at all?

    A
    B
    C
    D
    1
    15654:27
    8782:28
    24436:55
    C1: =A1+B1

    This should give ON MS-off ver 2007,2010

    A
    B
    C
    D
    1
    15654:27
    8782:28
    #VALUE!
    C1: =A1+B1

  9. #9
    Registered User
    Join Date
    01-27-2014
    Location
    kathmandu
    MS-Off Ver
    Microsoft Excel for Mac version 16.68, Office LTSC
    Posts
    33

    Re: range and vb function

    Quote Originally Posted by MrShorty View Post
    It might help if you could be more specific about the error you are getting. What is the error? What line/statement triggers the error?
    I understand your logic sir. However You may want to take a look at the screen shot as I feel I may not have explained my issue properly.

    Attachment 294373

  10. #10
    Registered User
    Join Date
    01-27-2014
    Location
    kathmandu
    MS-Off Ver
    Microsoft Excel for Mac version 16.68, Office LTSC
    Posts
    33

    Re: range and vb function

    Deleted. (double post)
    Last edited by pannam; 02-02-2014 at 10:27 AM.

  11. #11
    Forum Guru
    Join Date
    04-13-2005
    Location
    North America
    MS-Off Ver
    2002/XP and 2007
    Posts
    15,819

    Re: range and vb function

    Sorry I'm late. I must have missed your last post.

    As shg says, I don't see a need for a UDF to add times (assuming they are actual date/time values and not just text strings that look like time values). Assuming these are actual date/time serial values, the built in SUM() function should be able to add them up (or subtract them) just fine. However, assuming that you still want to pursue using this as an educational exercise for coding UDF's, here is my observation.

    There is a fundamental difference between the function all =st(a1,b1) and =st(a1:e1) -- especially as it relates to the function as coded. As coded, the function requires two range arguments. The first function call [=st(a1,b1)] has two arguments and so the function can execute (as long as there are not other errors). The latter function call [=st(a1:e1) assuming that is what you are trying to do] passes only one argument. So Excel/VBA throws an error because you have passed only one argument to a function that requires two arguments.

    I almost never use them, but I think what you might be wanting here is a single parametric array argument.

    Help file for Function statement that introduces the use of the paramarray keyword for designating parametric arrays http://msdn.microsoft.com/en-us/libr.../gg264233.aspx
    Tutorial explaining how to use parametric arrays in UDF's http://www.tushar-mehta.com/publish_...ramArray.shtml
    Another tutorial: http://www.cpearson.com/excel/Option...rocedures.aspx

    This is also probably going to require some restructuring of the rest of the code to cope with the paramarray. As I said at the beginning, I almost never use parametric arrays, so I'm not very good at using them. But the examples/tutorials given should give you a good introduction to the concept.

  12. #12
    Registered User
    Join Date
    01-27-2014
    Location
    kathmandu
    MS-Off Ver
    Microsoft Excel for Mac version 16.68, Office LTSC
    Posts
    33

    Re: range and vb function

    got what i was looking for here

    http://www.excel-easy.com/vba/range-object.html

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Replies: 15
    Last Post: 09-10-2013, 05:31 AM
  2. Function CountColor(rColor As Range, rSumRange As Range)
    By DawnEllis in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 07-17-2013, 08:11 PM
  3. [SOLVED] Repeat Cut & Paste function with Range.offset function VBA
    By kitcargray in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 10-06-2012, 12:17 PM
  4. Pass range as variable to Range function
    By souvick in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 11-17-2011, 09:33 AM
  5. IF function for a range of numbers within another range
    By deafmetal in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 01-27-2008, 08:18 AM

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