+ Reply to Thread
Results 1 to 2 of 2

How to use a public function in a similar way as worksheetfunction in VBA?

Hybrid View

  1. #1
    Registered User
    Join Date
    11-23-2012
    Location
    Antwerp, Belgium
    MS-Off Ver
    Excel 2010
    Posts
    1

    How to use a public function in a similar way as worksheetfunction in VBA?

    Hi,

    I’m writing a very large VBA macro to analyze data from multiple worksheets. All my functions are used in the following form (example):

    ReDim TotVAKWNAArray(1 To 5)
        For bCount = 1 To 5
            TotVAKWNAArray(bCount) = Application.WorksheetFunction.CountIfs(Range("D:D"), VAKW, Range("AW:AW"), "1", Range("N:N"), ToerReg, Range("K:K"), Prov, Range("W:W"), Gem)
            If ActiveSheet.Index = 5 Then
            Worksheets(1).Select
            Else
            ActiveSheet.Next.Select
            End If
        Next bCount
    Now, at the end of a laborious process, I need to use a function in the macro, that is not a standard Excel worksheet function (counting conditional unique values). I managed to find a public function that does the trick perfectly (here called UniqueCountv4). If I try to use this like in the example things go wrong. Is there anyone who knows how to fix this problem? I would be REALLY grateful I anyone could provide me with a solution.

        ReDim TotVAKLArray(1 To 5)
        For bCount = 1 To 5
            TotVAKLArray(bCount) = Application.WorksheetFunction.UniqueCountv4(Range("B:B"), Range("D:D"), VAKL) ', Range("N:N"), ToerReg, Range("K:K"), Prov, Range("W:W"), Gem)
            If ActiveSheet.Index = 5 Then
            Worksheets(1).Select
            Else
            ActiveSheet.Next.Select
            End If
        Next bCount
    Who can help me?

    Steven Laporte

    Moderators Note:
    Hello Steven & Welcome to the Board,
    Please follow Forum Rule #3 about the use of code tags. Added for you this time, but please use them in the future…Thanks.
    Last edited by jeffreybrown; 01-06-2013 at 10:04 AM.

  2. #2
    Forum Expert
    Join Date
    07-16-2010
    Location
    Northumberland, UK
    MS-Off Ver
    Excel 2007 (home), Excel 2010 (work)
    Posts
    3,054

    Re: How to use a public function in a similar way as worksheetfunction in VBA?

    Your user-defined function is not part of the Application.WorksheetFunction object, so it can't be called that way, but it should be fine to just do this:

    TotVAKLArray(bCount) = UniqueCountv4(Range("B:B"), Range("D:D"), VAKL) ', Range("N:N"), ToerReg, Range("K:K"), Prov, Range("W:W"), Gem)

+ 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