Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

data type of cell

Status
Not open for further replies.

maswien

Technical User
Joined
Sep 24, 2003
Messages
1,286
Location
CA

If I type a string to a cell in the sheet, in an excel macro, is there any data type difference on what I type in the cell?

I mean, if I type '12/30/1999' or 'asdasd', does excel know one is a date and another is a string?

If excel know the difference, how it use the data type in the macro?

Thanks
 
Hi
I'm not sure I really understand your question but as a bit of help......

Excel will understand different data types as you type them into a cell, although, Double is used for all numeric types.

To demonstrate this enter this code into a module

Code:
Function DataType(r As Range) As String
Application.Volatile
DataType = TypeName(r.Value)
End Function

In cell B2 of any sheet enter =DATATYPE(A1)
Then type different thing into A1

Note that after you enter a date the cell will format as a date so you may need to change it back if you wish to carry on testing with numeric values.

;-)

If a man says something and there are no women there to hear him, is he still wrong? [ponder]
The faqs ma'am, just the faqs. Get the best from these forums : faq222-2244
 
mjia,
If the macro is drawing data from the worksheet, it will need to know (or test) what type of data is there.

A variant variable can hold any type of data, and you can test whether it contains a number, error value or text string using
Code:
If IsError(myVariant) Or IsNumeric(myVariant) Then
It is also convenient (and much faster) to grab an entire range of cell data in a Variant array using a statements like:
Code:
 Dim myArray As Variant
Dim i As Long, j As Long
myArray=Range("A1:D500").Value   'Gets the data from the spreadsheet really fast
myArray(i,j)=152    'Or any other statement referencing or changing the value
Range("A1:D500").Value=myArray    'Puts the revised data back to the spreadsheet really fast
Brad
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top