+ Reply to Thread
Results 1 to 19 of 19

Macro giving wrong result for counting rows

  1. #1
    Registered User
    Join Date
    03-06-2014
    Location
    india
    MS-Off Ver
    Excel 2010
    Posts
    47

    Macro giving wrong result for counting rows

    Hi,

    The below code is giving wrong error.
    Please Login or Register  to view this content.

    sheet1 has the following data
    sheet1 has the following data

    empid name loc
    1 aaaa ddd
    2 bbbb ggg

    4 cccc dddd


    the 3rd row is empty in sheet1 but still it is showing number of rows as 3.I need macro it will not count if entire row is empty in that sheet.

  2. #2
    Registered User
    Join Date
    03-06-2014
    Location
    india
    MS-Off Ver
    Excel 2010
    Posts
    47

    Re: Macro giving wrong result for counting rows

    sorry it is showing number of rows as 4 instaed of 3.

  3. #3
    Forum Contributor
    Join Date
    03-04-2014
    Location
    Canada Eh
    MS-Off Ver
    Excel 2010
    Posts
    199

    Re: Macro giving wrong result for counting rows

    This will do as you ask
    Please Login or Register  to view this content.
    Click the * to give Rep to a post you like.

  4. #4
    Registered User
    Join Date
    03-06-2014
    Location
    india
    MS-Off Ver
    Excel 2010
    Posts
    47

    Re: Macro giving wrong result for counting rows

    Hi mad-mizer,

    I tried with your code but it is not giving any result.

  5. #5
    Forum Contributor
    Join Date
    03-04-2014
    Location
    Canada Eh
    MS-Off Ver
    Excel 2010
    Posts
    199

    Re: Macro giving wrong result for counting rows

    How did you apply it to your code? Please provide what you did as I cannot read your mind with regards to why it is not giving any result.

  6. #6
    Registered User
    Join Date
    03-06-2014
    Location
    india
    MS-Off Ver
    Excel 2010
    Posts
    47

    Re: Macro giving wrong result for counting rows

    Hi ,

    Please check the code.I have added one command button and in that i applied below code..
    Please Login or Register  to view this content.

  7. #7
    Forum Contributor
    Join Date
    03-04-2014
    Location
    Canada Eh
    MS-Off Ver
    Excel 2010
    Posts
    199

    Re: Macro giving wrong result for counting rows

    Oh so you want to see a message box with the row count, sorry:
    Please Login or Register  to view this content.

  8. #8
    Registered User
    Join Date
    03-06-2014
    Location
    india
    MS-Off Ver
    Excel 2010
    Posts
    47

    Re: Macro giving wrong result for counting rows

    Hi Mad-Mizer,

    The above code is ok But when first column data value is coming as null then it is not counting.we have chance of getting null values in some fields.If there is no data in that row then it will not include that row in count.But for below scenario it is failing.
    empid name address
    1 2 3
    1 2 3
    1 2 3
    2
    3

    1 2 3
    2 2 3
    2 3
    Count should be 8.but it is hsowing as 5.

  9. #9
    Registered User
    Join Date
    03-06-2014
    Location
    india
    MS-Off Ver
    Excel 2010
    Posts
    47

    Re: Macro giving wrong result for counting rows

    empid name address
    1 aaaa aaaa
    2 bbbb bbbb
    3 bbbb gggg
    bbbb
    bbbb

    6 bbbbb hghh
    5 gfgfgfg hhhh
    hhhh hhhh
    sample data...

  10. #10
    Registered User
    Join Date
    03-06-2014
    Location
    india
    MS-Off Ver
    Excel 2010
    Posts
    47

    Re: Macro giving wrong result for counting rows

    Sorry ihave data format issues whenever first value coming as null in row it is not counting.
    it should count that record bcz remaining columns having data in that row.If entire row is empty then it should not calculate that row.
    Last edited by aniletc37; 03-10-2014 at 09:55 AM.

  11. #11
    Forum Contributor
    Join Date
    03-04-2014
    Location
    Canada Eh
    MS-Off Ver
    Excel 2010
    Posts
    199

    Re: Macro giving wrong result for counting rows

    Maybe:
    Please Login or Register  to view this content.

  12. #12
    Registered User
    Join Date
    03-06-2014
    Location
    india
    MS-Off Ver
    Excel 2010
    Posts
    47

    Re: Macro giving wrong result for counting rows

    Hi Mad-mizer,

    Till if any of the column data is coming as null in any row that record is not counting.

  13. #13
    Forum Moderator Fotis1991's Avatar
    Join Date
    10-11-2011
    Location
    Athens(The homeland of the Democracy!). Greece
    MS-Off Ver
    Excel 1997!&2003 & 2007&2010
    Posts
    13,744

    Re: Macro giving wrong result for counting rows

    Your post does not comply with Rule 8 of our Forum RULES. Do not crosspost your question on multiple forums without including links here to the other threads on other forums.

    Cross-posting is when you post the same question in other forums on the web. The last thing you want to do is waste people's time working on an issue you have already resolved elsewhere. We prefer that you not cross-post at all, but if you do (and it's unlikely to go unnoticed), you MUST provide a link (copy the url from the address bar in your browser) to the cross-post.

    Expect cross-posted questions without a link to be closed and a message will be posted by the moderator explaining why. We are here to help so help us to help you!

    Read this to understand why we ask you to do this, and then please edit your first post to include links to any and all cross-posts in any other forums (not just this site).


    (This thread should receive no further responses until this moderation request is fulfilled, as per Forum Rule 7)
    Regards

    Fotis.

    -This is my Greek whisper to Europe.

    --Remember, saying thanks only takes a second or two. Click the little star * below, to give some Rep if you think an answer deserves it.

    Advanced Excel Techniques: http://excelxor.com/

    --KISS(Keep it simple Stupid)

    --Bring them back.

    ---See about Acropolis of Athens.

    --Visit Greece.

  14. #14
    Registered User
    Join Date
    03-06-2014
    Location
    india
    MS-Off Ver
    Excel 2010
    Posts
    47

    Re: Macro giving wrong result for counting rows

    ok I agree and confirm that I will absolutely abide by the "cross post" rule in future

  15. #15
    Registered User
    Join Date
    03-01-2014
    Location
    Hyderabad
    MS-Off Ver
    Excel 2003
    Posts
    13

    Lightbulb Re: Macro giving wrong result for counting rows

    Hi aniletc37,

    You can use:

    Wbk.Worksheets("SheetName").Cells(Rows.Count, ColumnNumber).End(xlUp).Row)

  16. #16
    Forum Moderator Fotis1991's Avatar
    Join Date
    10-11-2011
    Location
    Athens(The homeland of the Democracy!). Greece
    MS-Off Ver
    Excel 1997!&2003 & 2007&2010
    Posts
    13,744

    Re: Macro giving wrong result for counting rows

    Quote Originally Posted by aniletc37 View Post
    ok I agree and confirm that I will absolutely abide by the "cross post" rule in future
    Unfortunately this is not enough! You need to add a link to your first post with your thread in the other forum.

  17. #17
    Registered User
    Join Date
    03-06-2014
    Location
    india
    MS-Off Ver
    Excel 2010
    Posts
    47

    Re: Macro giving wrong result for counting rows

    HI,

    LINK IS BELOW FOR THAT POST...

    http://www.mrexcel.com/forum/excel-q...ting-rows.html

  18. #18
    Registered User
    Join Date
    03-06-2014
    Location
    india
    MS-Off Ver
    Excel 2010
    Posts
    47

    Re: Macro giving wrong result for counting rows

    Hi Gaurav,

    I'm very new to vbscript.Can you please tell me where i can place your code
    Please Login or Register  to view this content.
    In below code,
    Please Login or Register  to view this content.
    Some of the team members are provided some solution for this post in forum.Thx for your help.but the only problem is
    if any of the column data is coming as null in that row.It is not counting that record.
    Especially first coulmn value as null in that row then it is failing...

  19. #19
    Forum Contributor
    Join Date
    03-04-2014
    Location
    Canada Eh
    MS-Off Ver
    Excel 2010
    Posts
    199

    Re: Macro giving wrong result for counting rows

    I've rerun the code solution I gave you and it performed properly for me. Please upload the workbook in question for analysis.

+ 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. [SOLVED] Using Offset function as the array in the PercentRank function is giving wrong result
    By Bobneil in forum Excel Formulas & Functions
    Replies: 12
    Last Post: 08-06-2013, 09:29 PM
  2. [SOLVED] Ascending with macro make wrong result.
    By abjac in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 12-06-2012, 08:13 AM
  3. formula giving wrong result sometimes?
    By lnjr in forum Excel General
    Replies: 2
    Last Post: 08-13-2010, 09:20 AM
  4. Wrong result returned by UsedRange.Rows.Count
    By j in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 06-20-2005, 04:05 PM
  5. IF function giving wrong result
    By dzorug in forum Excel Formulas & Functions
    Replies: 6
    Last Post: 02-23-2005, 11:41 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