+ Reply to Thread
Results 1 to 4 of 4

Cell content FLOAT ?

  1. #1
    Registered User
    Join Date
    10-15-2008
    Location
    India
    Posts
    11

    Cell content FLOAT ?

    Hi,

    Is there any function or any way by which i get to know that cell content is integer or Floting?

    I need to findout in my VBA code if the cell content is floating if yes then truncate the contents to 6 decimal places

    My vBA code is something like below

    I want code to check that Cf1 and CF2 is float if yes

    then trun cate to 6 decimal places like


    Please Login or Register  to view this content.
    Please help how to do that Iam stuck up with this
    Many thanks,
    Ankur

  2. #2
    Valued Forum Contributor rwgrietveld's Avatar
    Join Date
    09-02-2008
    Location
    Netherlands
    MS-Off Ver
    XL 2007 / XL 2010
    Posts
    1,671

    re: Cell content FLOAT ?

    In programming you should not ask what the type is but determine it by the Dim statement.

    As VBA is working with Cell values you do not know the type at forehand and therefore Variant can be used. Having this you can convert it to any type you like with functions like CDbl(expression), CInt(expression)

    In your case make the cell variable a variant at first and typecast it to you single or double (Float) or integer (Int) by using CDbl() or CInt()

    Good Luck
    Looking for great solutions but hate waiting?
    Seach this Forum through Google

    www.Google.com
    (e.g. +multiple +IF site:excelforum.com/excel-general/ )

    www.Google.com
    (e.g. +fill +combobox site:excelforum.com/excel-programming/ )

    Ave,
    Ricardo

  3. #3
    Registered User
    Join Date
    10-15-2008
    Location
    India
    Posts
    11
    Hi,
    Thanks for the useful information however this might not solve my purpose by using the expressions above I can convest the cell vale, content of a variavle to float or Int however in my excel sheet its having lots of data which are of type integers, float & date & alpanumerics also (varchars)

    So if I set the varaible to float it will convert all the cell data of sheet to float which i dont want.

    I want a func which can determine that cel content or variable is float then perfom a action.

    Do we have any inbuilt function like that in VBA ?

    please help

  4. #4
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,438
    The builtin function determines data type of variables not values.
    You can use code to determine float or int.

    in cells A1:A4 enter
    1
    2
    1.2
    Test Text


    Leave A5 empty

    Please Login or Register  to view this content.
    Cheers
    Andy
    www.andypope.info

+ 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