Consulting

Results 1 to 4 of 4

Thread: CountIf with variable Range

  1. #1
    VBAX Regular
    Joined
    Oct 2007
    Posts
    97
    Location

    CountIf with variable Range

    Hi guys,
    I am trying to write a code that can count the number of letter "u" between two cells.
    a = 32
    b = 40
    C = 35

    [VBA]Cells(C, "Z") = "=COUNTIF(Range(Cells(35,a),Cells(35,b)),""u"")"[/VBA]

    Not working !! what I am doing wrong?

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Is this what you mean

    Cells(C, "Z") = Application.CountIf(Range(Cells(a, "A"), Cells(b, "A")), "u")
    Last edited by Aussiebear; 04-09-2023 at 04:35 AM. Reason: Adjusted the code tags
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  3. #3
    VBAX Regular
    Joined
    Oct 2007
    Posts
    97
    Location
    Thanks Xld,
    so the trick was to use application.
    Just curious, why recording a macro doesn't use "Application."?

  4. #4
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Because recording puts the formula into the formula property, you were trying to stuff it into value, but even then not using the correct values.
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •