+ Reply to Thread
Results 1 to 3 of 3

WorksheetFunction in VBA

Hybrid View

  1. #1
    Registered User
    Join Date
    01-03-2009
    Location
    Chicago,IL
    MS-Off Ver
    Excel 2007
    Posts
    11

    WorksheetFunction in VBA

    My workbook has a sheet called "MyList", another called "HisList" , a named range called "myNamedRange" which is "MyList!A:A".

    How do I get this functionality of this excel formula

     Countif(MyList!A:A, HisList!A1)
    in this vba code

    dblvalue=application.worksheetFunction(...)
    msgbox dblvalue
    The following code works with a named range
    wsHisList = Worksheets("HisList").Range("A1").offset(0,0).value
    Application.worksheetFunction(Range("myNamedRange"), wsHisList)
    My question is how can I use "MyList!A:A" directly in the worksheet function.

    Thanks
    Last edited by MacroLide; 01-20-2009 at 06:02 AM. Reason: Typo

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

    dblvalue = Application.WorksheetFunction.CountIf(Sheets("MyList").Columns(1),Sheets("HisList").Cells(1,"A"))
    (note you can use Application.CountIf also (ie dispose of WorksheetFunction))

    or you can use Evaluate

    dblValue = Application.Evaluate("COUNTIF(MyList!A:A,HisList!A1)")

  3. #3
    Registered User
    Join Date
    01-03-2009
    Location
    Chicago,IL
    MS-Off Ver
    Excel 2007
    Posts
    11
    Thank you very much

+ 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