+ Reply to Thread
Results 1 to 5 of 5

VBA function doesn't work properly

  1. #1
    Forum Contributor
    Join Date
    07-22-2008
    Location
    Dhaka, Bangladesh
    MS-Off Ver
    2007
    Posts
    130

    VBA function doesn't work properly

    I can't understand why my rate1() function (my macro) doesn't work properly. While I'm dragging M5 cell in Sheet2 down to M14 cell it gives the wrong result. Even when I change value in Sheet1 and refresh data of pivot table in Sheet2, my function rate1() isn't updated. But my problem is solving (getting the correct result) when I'm going Edit Mode (pressing function key F2) in active Cell M5 or M6 or M7..so on and pressing Enter each time.

    Is there any explanation?
    Attached Files Attached Files
    Last edited by sumonrezadu; 08-28-2009 at 09:39 AM.

  2. #2
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: VBA function doesn't work properly

    Only one cell is ever "Active" so your UDF in it's present form can only ever return the string for the active cell, you need therefore to pass a range reference to the UDF so it knows to which data it should be referring when generating the string, eg:

    Please Login or Register  to view this content.
    Called from your cell as:

    Please Login or Register  to view this content.
    You could do the same thing with native functions if preferred...

    Please Login or Register  to view this content.

  3. #3
    Forum Contributor
    Join Date
    07-22-2008
    Location
    Dhaka, Bangladesh
    MS-Off Ver
    2007
    Posts
    130

    Re: VBA function doesn't work properly

    Thanks a lot. Now I fathom. It really help me much. Many many thanks again.
    But could it be possible to get my desired result from my DataSheet? That is without generating Pivot Table how can I get desired result in another sheet using formula or function?
    Attached Files Attached Files

  4. #4
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: VBA function doesn't work properly

    You could certainly write code to do it but IMO the PT is an effective approach given that in essence the code "could" be relatively slow given the need to either a) iterate records or b) apply filters etc...
    all in all a subroutine seems a little unnecessary given the PT gives you the requisite info to populate your final output easily enough.

  5. #5
    Forum Contributor
    Join Date
    07-22-2008
    Location
    Dhaka, Bangladesh
    MS-Off Ver
    2007
    Posts
    130

    Re: VBA function doesn't work properly

    Yea, I agree with you. Thanks

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Tags for this Thread

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