+ Reply to Thread
Results 1 to 13 of 13

VarType(Cell) for a integer and a demical both are Type Long

  1. #1
    Forum Contributor
    Join Date
    04-02-2017
    Location
    Australia
    MS-Off Ver
    2016
    Posts
    403

    VarType(Cell) for a integer and a demical both are Type Long

    Hi guys,


    I am trying to get vba to give me TRUE only for integers.
    Both numbers are Type long within the watches window however the numbers are "5" and "3.5".

    how can I distinguish between these numbers and other numbers to find ones that are integers even though all the numbers seem to be classified as "Long" type within vba.

    Thanks,
    Jimmy

  2. #2
    Forum Contributor
    Join Date
    04-02-2017
    Location
    Australia
    MS-Off Ver
    2016
    Posts
    403

    Re: VarType(Cell) for a integer and a demical both are Type Long

    This is my current solution but I dislike it a lot.

    Please Login or Register  to view this content.

  3. #3
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,519

    Re: VarType(Cell) for a integer and a demical both are Type Long

    Do you want to find out the data type?
    Please Login or Register  to view this content.

  4. #4
    Forum Contributor
    Join Date
    04-02-2017
    Location
    Australia
    MS-Off Ver
    2016
    Posts
    403

    Re: VarType(Cell) for a integer and a demical both are Type Long

    Quote Originally Posted by jindon View Post
    Do you want to find out the data type?
    Please Login or Register  to view this content.

    Hey buddy

    I know the datatype, it is shown in the "Watch window"
    Expression.......Value.................Type
    Cell.................. 5 .................... Long
    (I require TRUE for this iteration)

    on the next iteration
    Expression.......Value.................Type
    Cell................ 3.5 ...................Long
    (I require FALSE for this iteration)

    So VarType(Cell) is giving me TRUE for both cases.
    Last edited by JimmyWilliams; 10-30-2017 at 09:34 PM.

  5. #5
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,519

    Re: VarType(Cell) for a integer and a demical both are Type Long

    I don't know how you declared Cell but if you dimension as Range it should return "Range" without Value property.

    Please Login or Register  to view this content.

  6. #6
    Forum Guru
    Join Date
    03-02-2006
    Location
    Los Angeles, Ca
    MS-Off Ver
    WinXP/MSO2007;Win10/MSO2016
    Posts
    12,607

    Re: VarType(Cell) for a integer and a demical both are Type Long

    Something is wrong.
    3.5 is not a Long, it is a Double. Longs are 4 byte integers ( whole numbers with zero decimal places). If you want to test for decimal fractions, maybe
    remainder = cell - int(cell)
    if remainder =0 then whole number
    Ben Van Johnson

  7. #7
    Forum Contributor
    Join Date
    04-02-2017
    Location
    Australia
    MS-Off Ver
    2016
    Posts
    403

    Re: VarType(Cell) for a integer and a demical both are Type Long

    3.png

    5.png


    I totally agree with you in theory, but its not what VBA wants to do!
    *Both 5 and 3.5 are type "double", which doesn't help, because I need a way to distinguish them (I had hoped "5" would return as a vbInteger 2 and "3.5" would return as a vbDecimal 14)


    The above photos show the watch window of the values. Below is the code I am using.
    And this link:
    https://www.excelforum.com/excel-pro...ml#post4774649
    is a copy of my spreadsheet I am using.




    Please Login or Register  to view this content.
    Last edited by JimmyWilliams; 10-30-2017 at 10:17 PM. Reason: Adding more information

  8. #8
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,519

    Re: VarType(Cell) for a integer and a demical both are Type Long

    That's maybe the type of the RETURNED value ,which is 5, from VarType function.

    Do a step debug with LocaWindow open, you will see all the variables and types.
    Please Login or Register  to view this content.
    x = Double
    y = Long

    .... Still something is wrong...
    If you use TypeName(x), it will return "Double" though.
    Last edited by jindon; 10-30-2017 at 10:54 PM.

  9. #9
    Forum Contributor
    Join Date
    04-02-2017
    Location
    Australia
    MS-Off Ver
    2016
    Posts
    403

    Re: VarType(Cell) for a integer and a demical both are Type Long

    Quote Originally Posted by jindon View Post
    Do a step debug with LocaWindow open, you will see all the variables and types.
    ... locals window?
    I'll play around with it but Ive never seen the locals window before...
    View > Locals Window... hmmmm

    I'll be back in a bit once I've had a look at this.

  10. #10
    Forum Contributor
    Join Date
    04-02-2017
    Location
    Australia
    MS-Off Ver
    2016
    Posts
    403

    Re: VarType(Cell) for a integer and a demical both are Type Long

    Quote Originally Posted by jindon View Post
    Do a step debug.
    My understanding of debugging is "press F8 (and use breaks too) and use the watch window until you find something that doesn't work right"

    Am I missing something I should know?
    Last edited by JimmyWilliams; 10-31-2017 at 12:06 AM. Reason: spelling

  11. #11
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,519

    Re: VarType(Cell) for a integer and a demical both are Type Long

    If you want to do a step debug for a Function, set a break point, click on a bar left to the code module, or insert Stop somewehe, so that you can go into a debug mode.

  12. #12
    Forum Contributor
    Join Date
    04-02-2017
    Location
    Australia
    MS-Off Ver
    2016
    Posts
    403

    Re: VarType(Cell) for a integer and a demical both are Type Long

    hey mate,

    you wouldn't happen to know a better way to write

    Please Login or Register  to view this content.
    That would probably help a bit.

  13. #13
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,519

    Re: VarType(Cell) for a integer and a demical both are Type Long

    Not really sure though...
    Please Login or Register  to view this content.

+ 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] carrying integer (or long) value from one sub to another sub
    By ElianaMG in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 02-06-2015, 03:05 PM
  2. [SOLVED] Overflow when assigning a value to an Integer Data Type
    By Speshul in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 09-03-2014, 09:12 AM
  3. Replies: 1
    Last Post: 11-14-2013, 05:01 AM
  4. [SOLVED] Long variable returning unexpected result which appears to be only integer value
    By welchs101 in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 07-05-2013, 10:59 AM
  5. Integer vs long vs decimal
    By mtclimber in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 02-25-2009, 08:18 PM
  6. Declaring INTEGER vrs. LONG
    By davidm in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 12-07-2006, 01:36 AM
  7. Problem using names as integer type
    By TJI in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 04-07-2006, 07:35 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