Results 1 to 3 of 3

Thread: Determine data type

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Jul 2005
    Posts
    394

    Determine data type

    I'm using typeof to determine the type of an object and keep getting an error that says: Argument 'Number' cannot be converted to a numeric value. The error occurs on bold line below.

    vb Code:
    1. [B]If TypeOf Str((CType(oShtData.Cells(2, 1), Excel.Range).Value)) Is String Then[/B]
    2.             'Copy variable names from the data worksheet.  This data was imported form the CSV
    3.             CType(oShtData.Rows(2), Excel.Range).Copy()
    4.             'Transpose and Paste the data into the Control worksheet
    5.             CType(oShtCont.Cells(2, 8), Excel.Range).PasteSpecial(Excel.XlPasteType.xlPasteValues, , , True)
    6.         End If

    If I debug the this line it looks fine. The difference is that I cannot use ctype in the watch window.
    Attached Images Attached Images  
    Last edited by campster; Apr 17th, 2007 at 02:26 PM.

  2. #2

    Thread Starter
    Hyperactive Member
    Join Date
    Jul 2005
    Posts
    394

    Re: Determine data type

    Ok, here's a subtlety that I don't understand. The line below works

    Code:
    If TypeOf CType(oShtData.Cells(2, 1), Excel.Range).Text.ToString Is String Then
    Edit: Nevermind. It worked in the sense that it didn't throw an error but it did not logically work. Because I "converted" the data to a string, everything was a string and I got data that I didn't want.
    Last edited by campster; Apr 17th, 2007 at 02:32 PM.

  3. #3
    PowerPoster VBDT's Avatar
    Join Date
    Sep 2005
    Location
    CA - USA
    Posts
    2,922

    Re: Determine data type

    try this
    vb Code:
    1. If TypeOf CType(oShtData.Cells(2, 1), Excel.Range).Value Is String Then
    2.  
    3.  End If

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width