+ Reply to Thread
Results 1 to 4 of 4

DataType Property

  1. #1
    Access101
    Guest

    DataType Property

    The Excel HELP file demonstrates how to test for data types in a PivotTABLE:

    Set pvtTable = Worksheets("Sheet1").Range("A3").PivotTable
    Select Case pvtTable.PivotFields("ORDER_DATE").DataType
    Case Is = xlText
    MsgBox "The field contains text data"
    Case Is = xlNumber
    MsgBox "The field contains numeric data"
    Case Is = xlDate
    MsgBox "The field contains date data"
    End Select

    How do I test for DataTypes in a cell in a regular worksheet (my crude
    attempts are)

    msgbox ActiveCell.DataType
    msgbox Range("A1").DataType


  2. #2
    Tom Ogilvy
    Guest

    Re: DataType Property

    vartype(activecell)

    See help on Vartype for the constant values returned.

    --
    Regards,
    Tom Ogilvy


    "Access101" <[email protected]> wrote in message
    news:[email protected]...
    > The Excel HELP file demonstrates how to test for data types in a

    PivotTABLE:
    >
    > Set pvtTable = Worksheets("Sheet1").Range("A3").PivotTable
    > Select Case pvtTable.PivotFields("ORDER_DATE").DataType
    > Case Is = xlText
    > MsgBox "The field contains text data"
    > Case Is = xlNumber
    > MsgBox "The field contains numeric data"
    > Case Is = xlDate
    > MsgBox "The field contains date data"
    > End Select
    >
    > How do I test for DataTypes in a cell in a regular worksheet (my crude
    > attempts are)
    >
    > msgbox ActiveCell.DataType
    > msgbox Range("A1").DataType
    >




  3. #3
    Access101
    Guest

    Re: DataType Property

    Thanks for you help. I was hoping to be able to test for these DataTypes:

    'xlParamTypeBinary
    'xlParamTypeChar
    'xlParamTypeDecimal
    'xlParamTypeFloat
    'xlParamTypeLongVarBinary
    'xlParamTypeNumeric
    'xlParamTypeSmallInt
    'xlParamTypeTimestamp
    'xlParamTypeUnknown
    'xlParamTypeVarChar
    'xlParamTypeBigInt
    'xlParamTypeBit
    'xlParamTypeDate
    'xlParamTypeDouble
    'xlParamTypeInteger
    'xlParamTypeLongVarChar
    'xlParamTypeReal
    'xlParamTypeTime
    'xlParamTypeTinyInt
    'xlParamTypeVarBinary
    'xlParamTypeWChar

    "Tom Ogilvy" wrote:

    > vartype(activecell)
    >
    > See help on Vartype for the constant values returned.
    >
    > --
    > Regards,
    > Tom Ogilvy
    >
    >
    > "Access101" <[email protected]> wrote in message
    > news:[email protected]...
    > > The Excel HELP file demonstrates how to test for data types in a

    > PivotTABLE:
    > >
    > > Set pvtTable = Worksheets("Sheet1").Range("A3").PivotTable
    > > Select Case pvtTable.PivotFields("ORDER_DATE").DataType
    > > Case Is = xlText
    > > MsgBox "The field contains text data"
    > > Case Is = xlNumber
    > > MsgBox "The field contains numeric data"
    > > Case Is = xlDate
    > > MsgBox "The field contains date data"
    > > End Select
    > >
    > > How do I test for DataTypes in a cell in a regular worksheet (my crude
    > > attempts are)
    > >
    > > msgbox ActiveCell.DataType
    > > msgbox Range("A1").DataType
    > >

    >
    >
    >


  4. #4
    Tom Ogilvy
    Guest

    Re: DataType Property

    Numbers are stored as double

    If the number is formatted as currency, then it would return currency

    if the number is formatted as a date, then it would return a date

    then you have string, error and empty.

    All the constants that don't fit in that, you would ignore.

    Reference your posted sub:

    Case Is = xlText
    MsgBox "The field contains text data"
    Case Is = xlNumber
    MsgBox "The field contains numeric data"
    Case Is = xlDate
    MsgBox "The field contains date data"

    --
    Regards,
    Tom Ogilvy



    "Access101" <[email protected]> wrote in message
    news:[email protected]...
    > Thanks for you help. I was hoping to be able to test for these DataTypes:
    >
    > 'xlParamTypeBinary
    > 'xlParamTypeChar
    > 'xlParamTypeDecimal
    > 'xlParamTypeFloat
    > 'xlParamTypeLongVarBinary
    > 'xlParamTypeNumeric
    > 'xlParamTypeSmallInt
    > 'xlParamTypeTimestamp
    > 'xlParamTypeUnknown
    > 'xlParamTypeVarChar
    > 'xlParamTypeBigInt
    > 'xlParamTypeBit
    > 'xlParamTypeDate
    > 'xlParamTypeDouble
    > 'xlParamTypeInteger
    > 'xlParamTypeLongVarChar
    > 'xlParamTypeReal
    > 'xlParamTypeTime
    > 'xlParamTypeTinyInt
    > 'xlParamTypeVarBinary
    > 'xlParamTypeWChar
    >
    > "Tom Ogilvy" wrote:
    >
    > > vartype(activecell)
    > >
    > > See help on Vartype for the constant values returned.
    > >
    > > --
    > > Regards,
    > > Tom Ogilvy
    > >
    > >
    > > "Access101" <[email protected]> wrote in message
    > > news:[email protected]...
    > > > The Excel HELP file demonstrates how to test for data types in a

    > > PivotTABLE:
    > > >
    > > > Set pvtTable = Worksheets("Sheet1").Range("A3").PivotTable
    > > > Select Case pvtTable.PivotFields("ORDER_DATE").DataType
    > > > Case Is = xlText
    > > > MsgBox "The field contains text data"
    > > > Case Is = xlNumber
    > > > MsgBox "The field contains numeric data"
    > > > Case Is = xlDate
    > > > MsgBox "The field contains date data"
    > > > End Select
    > > >
    > > > How do I test for DataTypes in a cell in a regular worksheet (my crude
    > > > attempts are)
    > > >
    > > > msgbox ActiveCell.DataType
    > > > msgbox Range("A1").DataType
    > > >

    > >
    > >
    > >




+ 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