+ Reply to Thread
Results 1 to 4 of 4

Using variable as criteria for a countif

  1. #1
    Registered User
    Join Date
    02-20-2019
    Location
    Hobbiton,Shire
    MS-Off Ver
    Office 360
    Posts
    2

    Using variable as criteria for a countif

    Hi there,

    I am currently working on sorting and copying data from a very large data set into individual sheets. More specificaly, taking Meteorelogical data which is numberd with the station number, year, and date ie: 15901A1953010102. This is hourly data and am I trying to use a countif statement to find the number of hours for each year (which should be 8760 for a normal year and 8784 for a leap year). I am using a loop to go through each year of data which is available (being from 1953 to 2011). I want to then use the variable counter from my for loop as the criterion for my countit function. Using plainly [COUNTIF(A:A, "*1953*")] with the asterix's works fine however I am not sure how to slide in the variable counter. I don't have to much experience in coding but from what I think I know the problem is I am trying to use a string where I need a number? Here's my code:
    Please Login or Register  to view this content.
    I have the message box in there for now to see the output. If anybody could help me out that would be great!

    cheers,

    Moderator note: Added code tags.
    Last edited by FlameRetired; 02-20-2019 at 11:10 PM.

  2. #2
    Forum Expert Kenneth Hobson's Avatar
    Join Date
    02-05-2007
    Location
    Tecumseh, OK
    MS-Off Ver
    Office 365, Win10Home
    Posts
    2,573

    Re: Using variable as criteria for a countif

    Welcome to the forum!

    Please Login or Register  to view this content.

  3. #3
    Forum Moderator
    Join Date
    01-21-2014
    Location
    St. Joseph, Illinois U.S.A.
    MS-Off Ver
    Office 365 v 2403
    Posts
    13,406

    Re: Using variable as criteria for a countif

    Hello Lord_Lettuce. Welcome to the forum.

    As a new member you may not be aware of our forum rules.

    One of them is Rule 2: Use code tags around code.

    Posting code between [CODE]Please [url=https://www.excelforum.com/login.php]Login or Register [/url] to view this content.[/CODE] tags makes your code much easier to read and copy for testing, it also maintains VBA formatting.

    Click on Edit to open your thread, then highlight your code and click the # icon at the top of your post window. More information about these and other tags can be found here

    Since you are a new member I have gone ahead and done it for you.

    Thank you.
    Dave

  4. #4
    Registered User
    Join Date
    02-20-2019
    Location
    Hobbiton,Shire
    MS-Off Ver
    Office 360
    Posts
    2

    Re: Using variable as criteria for a countif

    Thank you for the welcome and the fast reply Kenneth Hobson! I tried it out and it works!

    Thank you for the welcome FlameRetired, I will make sure to not forget the code tags next time around!

    cheers,

+ 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. Countif with multiple variable criteria and wildcard "*"
    By joseph.davidow in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 11-09-2018, 12:30 PM
  2. [SOLVED] Counting cells that meet multiple single criteria as variable criteria
    By BillBasil in forum Excel Formulas & Functions
    Replies: 6
    Last Post: 02-01-2016, 10:33 AM
  3. Replies: 18
    Last Post: 09-08-2014, 05:06 PM
  4. Return dates that match a single criteria (a countif criteria)
    By nickmax1 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 02-07-2014, 12:43 PM
  5. Replies: 1
    Last Post: 10-27-2012, 02:54 AM
  6. [SOLVED] Vba countif with criteria being a variable row number
    By Estrella Linda in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 08-11-2012, 02:32 PM
  7. countif variable criteria
    By neda5 in forum Excel General
    Replies: 3
    Last Post: 05-03-2005, 06:06 AM

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