+ Reply to Thread
Results 1 to 10 of 10

Find missing numbers in a column

  1. #1
    Forum Contributor excelkeechak's Avatar
    Join Date
    07-21-2008
    Location
    India.
    MS-Off Ver
    2013 /2016
    Posts
    363

    Find missing numbers in a column

    i had a worksheet in which i had a column Named Cheque No. i want to print the missing cheque no's in a series of cheque no's.The logic here is that there will be different series of cheque nos for different transactions.Just check out my worksheet.
    Attached Files Attached Files

  2. #2
    Forum Expert Ron Coderre's Avatar
    Join Date
    03-22-2005
    Location
    Boston, Massachusetts
    MS-Off Ver
    2013, 2016, O365
    Posts
    6,996

    Re: Find missing numbers in a column

    Using your posted workbook....here's something to try.

    This regular formula returns a list of the missing check numbers:

    Please Login or Register  to view this content.
    Copy that formula down as far as you need.

    Note: the 650000 adjustments are necessary because we are using Row Numbers
    to simulate your series...and Excel 2003 only has 65,536 rows.

    In your example, these values are returned in H2:H4
    652001
    652003
    652004

    Is that something you can work with?
    Ron
    Former Microsoft MVP - Excel (2006 - 2015)
    Click here to see the Forum Rules

  3. #3
    Forum Contributor excelkeechak's Avatar
    Join Date
    07-21-2008
    Location
    India.
    MS-Off Ver
    2013 /2016
    Posts
    363

    Re: Find missing numbers in a column

    how to do the same using vba

  4. #4
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Find missing numbers in a column

    This will list the missing Checks in column J:
    Please Login or Register  to view this content.
    _________________
    Microsoft MVP 2010 - Excel
    Visit: Jerry Beaucaire's Excel Files & Macros

    If you've been given good help, use the icon below to give reputation feedback, it is appreciated.
    Always put your code between code tags. [CODE] your code here [/CODE]

    ?None of us is as good as all of us? - Ray Kroc
    ?Actually, I *am* a rocket scientist.? - JB (little ones count!)

  5. #5
    Forum Contributor excelkeechak's Avatar
    Join Date
    07-21-2008
    Location
    India.
    MS-Off Ver
    2013 /2016
    Posts
    363

    Re: Find missing numbers in a column

    By the way, can u tell me what this means:LastRow = Range("A" & Rows.Count).End(xlUp).Row
    i think i counts the cells down the column like A1,A2,A3 am i correct

  6. #6
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Find missing numbers in a column

    "Rows.Count" means "the last row in the entire workbook". This is different for different versions of Excel.

    "Range("A" & Rows.Count)" means "the last cell in column A in the entire workbook..." In Excel 2003 that's A65536.

    "Range("A" & Rows.Count).End(xlUp)" means "start at the last cell in column A and jump UP to the last cell with data in it.

    LastRow = Range("A" & Rows.Count).End(xlUp).Row means "remember the ROW# of the last cell in column A with data in it and call it "LastRow" for short, usable as a variable in other VBA code.

    ===================
    If that takes care of your need, be sure to EDIT your original post (Go Advanced) and mark the PREFIX box [SOLVED]

  7. #7
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: Find missing numbers in a column

    JB, re:

    Please Login or Register  to view this content.
    i & LastRow are Variants in the above, perhaps you meant ?

    Please Login or Register  to view this content.

  8. #8
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Find missing numbers in a column

    Someone recently indicated to me that:
    Please Login or Register  to view this content.
    ...was shorthand for:
    Please Login or Register  to view this content.
    Before that I had always used the latter, and as my formulas all continue to operate as expected when I used the shorthand, I surmised their suggestion was correct.

    Prior to that I had always thought that declaring JUST a variable name mean Variant, but this testing made me believe otherwise... (literally just days ago).

    So I was right in my original understanding, I DO need to declare in longhand? Why would my numerical(s) variable continue to function with no issues? Usually I get error messages when I use the wrong TYPE of variable.

  9. #9
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: Find missing numbers in a column

    In VBA

    Please Login or Register  to view this content.
    only C is Long, a & b are Variants ... whereas in .NET a, b & c would all be Long

    As to why your code works ... VBA is designed for non-programmers ie there is the expectation that Variables may not be declared at all - hence Option Explicit is not default setting.
    Anything not declared explicitly is assiged a Variant and a Variant can be anything hence the code works regardless...
    General school of thought is: Variants = Inefficient/Expensive, however, I've heard MS MVP's say recently (Simon Hodge) that they think that's not really that significant an issue in VBA and that in reality all Cells are Variants (and there are lots of those without impacting performance!).

    Note: In .NET, code is Option Explicit and the Variant type no longer exists (one must use Object)
    Last edited by DonkeyOte; 04-25-2009 at 11:13 AM. Reason: typos

  10. #10
    Forum Contributor excelkeechak's Avatar
    Join Date
    07-21-2008
    Location
    India.
    MS-Off Ver
    2013 /2016
    Posts
    363

    Re: Find missing numbers in a column

    Its nice to see those replies regarding my little doubts.I feel that they are significant i building up the code.really, thanks for the good explanation to both of u.

    I want to know the generalised formula(VBA SNIPPET) for using the code in any macro to check the last cell used /last cell in the column.Also do tell me what does & Mean.

+ 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