+ Reply to Thread
Results 1 to 6 of 6

assign the result of countif to a variable in VBA

  1. #1
    Registered User
    Join Date
    07-31-2010
    Location
    essex
    MS-Off Ver
    Excel 2007
    Posts
    12

    Smile assign the result of countif to a variable in VBA

    Hello all

    I need some help with excel 2007 please.

    How do I assign the result of the countif function to a variable in VBA instead of showing the result in a cell?

    something like

    loopcounter = "=COUNTIF(C[-6],""?*"")"

    cheers
    Last edited by lima; 09-22-2010 at 04:46 PM.

  2. #2
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: assign the result of countif to a variable in VBA

    It's a relative column reference, so it would have to be evaluated in the context of a particular column.
    Entia non sunt multiplicanda sine necessitate

  3. #3
    Registered User
    Join Date
    07-31-2010
    Location
    essex
    MS-Off Ver
    Excel 2007
    Posts
    12

    Re: assign the result of countif to a variable in VBA

    Thanks shg

    so apart from using something like loopcounter = activecell.value,
    is there a way to write code that will count cells in a coloum that have some content and put the result into a variable

  4. #4
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,425

    Re: assign the result of countif to a variable in VBA

    If you know which column you want to check, or which part of a column, and you know which cell holds the value you are looking for, you can have something like:

    Please Login or Register  to view this content.

    Or

    Please Login or Register  to view this content.

    Or

    Please Login or Register  to view this content.

    Regards

  5. #5
    Registered User
    Join Date
    07-31-2010
    Location
    essex
    MS-Off Ver
    Excel 2007
    Posts
    12

    Re: assign the result of countif to a variable in VBA

    Thanks TMShucks
    I’ve spent hours trying to write something like any of these 3 lines without success

    Come on you Reds, what a hat trick

    Best Regards

  6. #6
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,425

    Re: assign the result of countif to a variable in VBA

    Each to their own. I've been watching a professional tiler tiling my kitchen and thinking, "I wish I could do that".

    Thanks for the feedback.

    Regards

+ 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