Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 58
Default How to check a Variant for its data type

Windows 2k Pro
Excel 2000

I have a 1-dimensional array as Variant. The values are either a String or
an Integer. How do I loop through the array and check to see if a
particular value is a string or an integer?

Thanks!

-gk-


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default How to check a Variant for its data type

use typename or vartype

--
Regards,
Tom Ogilvy


TBA wrote in message
...
Windows 2k Pro
Excel 2000

I have a 1-dimensional array as Variant. The values are either a String

or
an Integer. How do I loop through the array and check to see if a
particular value is a string or an integer?

Thanks!

-gk-




  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default How to check a Variant for its data type

As an add-on question, what if you want to check if a string is a
integer or not? Do you need to manually check each character?

Thank

--
Message posted from http://www.ExcelForum.com

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default How to check a Variant for its data type

You can use the TypeName function to return the type of value
contained in the variant. For example,

Dim V As Variant
V = 123
Debug.Print TypeName(V)

You can determine whether a string is numeric by using the
IsNumeric function. For example,

Dim V As Variant
V = "1234"
Debug.Print IsNumeric(V)


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com



"Ripan " wrote in message
...
As an add-on question, what if you want to check if a string is

an
integer or not? Do you need to manually check each character?

Thanks


---
Message posted from http://www.ExcelForum.com/



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default How to check a Variant for its data type

Fair enough. IsNumeric makes the distinction between numeric and not
but what if I only want integers, and not floats

--
Message posted from http://www.ExcelForum.com



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default How to check a Variant for its data type

Try something like

Dim V As Variant
V = whatever
If IsNumeric(V) Then
If CInt(V) = CDbl(V) Then
Debug.Print "is integer"
Else
Debug.Print "not an integer"
End If
End If



--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com


"Ripan " wrote in message
...
Fair enough. IsNumeric makes the distinction between numeric

and not,
but what if I only want integers, and not floats?


---
Message posted from http://www.ExcelForum.com/



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
check spelling as you type dp New Users to Excel 5 February 3rd 10 07:00 PM
Check for error.type in same cell art Excel Worksheet Functions 2 May 13th 09 06:14 AM
check spelling automatically as you type by displaying red underli Scavenger Excel Discussion (Misc queries) 1 November 16th 07 11:59 PM
Excel: How do I type a letter in a column and make a check mark a. BauerY Excel Worksheet Functions 3 March 24th 05 06:34 PM
Variant to String Chip Pearson Excel Programming 1 September 3rd 03 03:10 PM


All times are GMT +1. The time now is 03:18 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"