+ Reply to Thread
Results 1 to 4 of 4

Compile Error using CountA

Hybrid View

  1. #1
    Forum Contributor dagindi's Avatar
    Join Date
    06-02-2008
    Location
    New York, NY
    MS-Off Ver
    Excel 2007 & 2010
    Posts
    295

    Compile Error using CountA

    I am getting a Compile error: Sub or Function not defined using the following code:

    Sub Macro1()
    Dim lastrow As Long
    With ActiveSheet
            lastrow = .Cells(.Rows.Count, "E").End(xlUp).Row
            Range("E1").Select
            ActiveCell.FormulaR1C1 = CountA("E3" & lastrow)
    End Sub

    Im assuming this has something to do with Lastrow code but I am not sure.

    I am trying to count all the cells with data in column E starting with cell E3 and using lastrow to find the last row.

    Data gets entered into E1.

  2. #2
    Forum Moderator jeffreybrown's Avatar
    Join Date
    02-19-2009
    Location
    Cibolo, TX
    MS-Off Ver
    Office 365
    Posts
    10,318

    Re: Compile Error using CountA

    How about


    Sub Macro1()
        Dim lastrow As Long
        With ActiveSheet
            lastrow = .Cells(.Rows.Count, "E").End(xlUp).Row
            Range("E1").Value = Application.CountA(Range(Cells(3, 5), Cells(lastrow, 5)))
        End With
    End Sub
    HTH
    Regards, Jeff

  3. #3
    Forum Contributor dagindi's Avatar
    Join Date
    06-02-2008
    Location
    New York, NY
    MS-Off Ver
    Excel 2007 & 2010
    Posts
    295

    Re: Compile Error using CountA

    jeffreybrown,

    I never used the Application.XYZ.

    Thanks for your help and for broadening my knowledge with this code.

  4. #4
    Forum Moderator jeffreybrown's Avatar
    Join Date
    02-19-2009
    Location
    Cibolo, TX
    MS-Off Ver
    Office 365
    Posts
    10,318

    Re: Compile Error using CountA

    You are most welcome. Thanks for the rep and thanks for marking as solved.

+ 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. [SOLVED] Compile Error: Wrong number of arguments or invalid property assignment Error
    By JJFletcher in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 04-22-2016, 05:29 PM
  2. Excel macro (compile error. syntax error.) error
    By salar_younis in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 01-06-2014, 06:11 AM
  3. [SOLVED] Compile Error in Hidden Module and Compile Error: Can't find project or library
    By Taislin in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 08-10-2013, 07:03 PM
  4. [SOLVED] Counta function-error!!!
    By CESAR V. ARROYO in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 08-06-2013, 07:56 PM
  5. CountA return error when one of the cell deleted
    By celticpucca in forum Excel General
    Replies: 3
    Last Post: 05-12-2011, 07:59 AM
  6. compile error: compile error expected
    By odeno in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 03-11-2008, 04:30 PM
  7. [SOLVED] VBAProject name compile error, not defined at compile time
    By Matthew Dodds in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 12-13-2005, 03:20 PM

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