+ Reply to Thread
Results 1 to 7 of 7

Search for strings

  1. #1
    Registered User
    Join Date
    06-21-2005
    Posts
    16

    Search for strings

    If I use the line of code (not using vba).......
    =COUNTIF(R1C1:R36C1,"COUNCIL TAX - General queries")

    ........ then it works fine.

    However if i put this into vba using a macro then it doesn't work.

    Application.WorksheetFunction.CountIf(range("R2C1:R35C1"), "COUNCIL TAX - General queries*")


    Totally stuck here,

    Will keep trying, but does anyone understand this

    Thanks Guys.

    Dave

  2. #2
    JE McGimpsey
    Guest

    Re: Search for strings

    From VBA Help (Range Property):

    > expression.Range(Cell1)
    >
    > Cell1 Required. The name of the range. This must be an A1-style
    > reference in the language of the macro.


    So try

    Application.WorksheetFunction.CountIf(Range("A2:A35"), _
    "COUNCIL TAX - General queries*")

    In article <[email protected]>,
    David494 <[email protected]> wrote:

    > If I use the line of code (not using vba).......
    > =COUNTIF(R1C1:R36C1,"COUNCIL TAX - General queries")
    >
    > ....... then it works fine.
    >
    > However if i put this into vba using a macro then it doesn't work.
    >
    > Application.WorksheetFunction.CountIf(range("R2C1:R35C1"), "COUNCIL TAX
    > - General queries*")
    >
    >
    > Totally stuck here,
    >
    > Will keep trying, but does anyone understand this
    >
    > Thanks Guys.
    >
    > Dave


  3. #3
    Registered User
    Join Date
    06-21-2005
    Posts
    16
    but i just get the same error message.

    Compile Error

    Expected: =

    .....I don't know what this error is.

    Thanks for helping

    Dave

  4. #4
    Registered User
    Join Date
    06-21-2005
    Posts
    16
    Strange, it seems to work when I msgBox it.

    E.g

    MsgBox (Application.WorksheetFunction.CountIf(Range("A2:A35"), "COUNCIL TAX - General queries*"))

  5. #5
    Registered User
    Join Date
    06-21-2005
    Posts
    16
    Strange, it seems to work when I msgBox it.

    E.g

    MsgBox (Application.WorksheetFunction.CountIf(Range("A2:A35"), "COUNCIL TAX - General queries*"))

  6. #6
    JE McGimpsey
    Guest

    Re: Search for strings

    In VBA, if you're not returning the value to a variable or method, you
    don't use the parens (see VBA Help "Using Parentheses in Code"), so the
    code would be

    Application.WorksheetFunction.CountIf Range("A2:A35"), _
    "COUNCIL TAX - General queries*"

    but that invokes the method without any purpose. Why are you calling
    CountIf if you're not going to use the result?

    In article <[email protected]>,
    David494 <[email protected]>
    wrote:

    >
    > but i just get the same error message.
    >
    > Compile Error
    >
    > Expected: =
    >
    > ....I don't know what this error is.


  7. #7
    Registered User
    Join Date
    06-21-2005
    Posts
    16
    Sorry for not getting back to you sooner, but i forgot all about this post. The message box does me fine, as i just want the user to know the number of times a string appears between two specified dates, then they can note down this value.

    Thanks for your help

    Dave

+ 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