tags:

views:

497

answers:

3

Hi , how do I express the term if x is integer in VBA language ? I want to write a code that does something if x is integer and does something else if its not with vba excel.

Sub dim()
  Dim x is Variant

  'if x is integer Then 

  'Else:

End Sub 
+4  A: 
If IsNumeric(x) Then 'it will check if x is a number

If you want to check the type, you could use

If TypeName(x) = "Integer" Then
shahkalpesh
ok thanks , btw onaside how do I add code tags?
excel34
You can either click the button in the editor that looks like 1s and 0s, or you can use nest your code in <pre> tags and then <code> tags. (You must do both). It's generally better to paste the code, highlight it, then click the button. But the editor can be finicky and sometimes it's less hassle to just manually put in the tags.
Oorang
+3  A: 

This may suit:

If x = Int(x) Then
Remou
I much prefer this to a solution using a hard-coded string.
ProfK
+4  A: 
Oorang