+ Reply to Thread
Results 1 to 10 of 10

Find missing numbers in a column

Hybrid View

  1. #1
    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:
    Dim i, LastRow, LastNum As Long
    ...was shorthand for:
    Dim i As Long, LastRow As Long, LastNum As Long
    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.
    _________________
    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!)

  2. #2
    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

    Dim a, b, c As Long
    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

+ 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