+ Reply to Thread
Results 1 to 4 of 4

Count rows below a range that as data

  1. #1
    Registered User
    Join Date
    08-07-2014
    Location
    Houston, Texas
    MS-Off Ver
    2010
    Posts
    22

    Count rows below a range that as data

    I'm trying to count the number of rows below a named range that have data in them, ending at the first blank cell. I'm getting an error message saying "Type mismatch" for the line containing the IF statement though.

    Please Login or Register  to view this content.

  2. #2
    Forum Expert
    Join Date
    07-31-2010
    Location
    California
    MS-Off Ver
    Excel 2007
    Posts
    4,070

    Re: Count rows below a range that as data

    Please Login or Register  to view this content.

  3. #3
    Registered User
    Join Date
    08-07-2014
    Location
    Houston, Texas
    MS-Off Ver
    2010
    Posts
    22

    Re: Count rows below a range that as data

    Thank you, stnkynts! It's returning the right number of rows. Do you have any suggestions on why I'm getting the type mismatch message for the IF statement. I thought specifying the .Value finding the range would allow me to do a comparison argument.

  4. #4
    Valued Forum Contributor
    Join Date
    03-21-2013
    Location
    cyberia
    MS-Off Ver
    Excel 2007
    Posts
    457

    Re: Count rows below a range that as data

    Your
    Please Login or Register  to view this content.
    doesn't make sense to your computer.

    The "cells" notation in VBA uses Cells(i, j) to describe the cell in the i-th row and j-th column of a worksheet. i.e. both i and j must be numbers, more specifically positive integers.

    Range("WTime") isn't an integer, it's a cell or group of cells so your type mismatch isn't surprising.

    If you like you could use
    Please Login or Register  to view this content.
    without getting a type mismatch (for the above reason anyway)


    Also, in your second line of code, if WTime is not a single cell then trying to compare it (or its offset which is not a single cell either) to a single value will also give type mismatch.
    You can set a range of more than one cell equal to some value but you can't compare it to a single value.
    e.g. try the codes
    Please Login or Register  to view this content.
    One will work and the other won't.
    Last edited by kalak; 08-31-2014 at 07:18 AM.

+ 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. Count rows of a filtered range
    By newbi004 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 10-29-2013, 06:30 AM
  2. [SOLVED] Range (Rows.Count) trouble
    By soli004 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 09-18-2012, 02:57 AM
  3. Count of Rows in Range ..... does not seem correct
    By welchs101 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 08-07-2011, 12:13 PM
  4. Count Rows and Use to Populate Range
    By SyracuseSteve in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 01-22-2010, 07:51 PM
  5. Range Selection-Is there anyway to count the rows?
    By MrHappy in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 01-18-2005, 02:06 PM

Tags for this Thread

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