ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Discussion (Misc queries) (https://www.excelbanter.com/excel-discussion-misc-queries/)
-   -   Declaring variables (https://www.excelbanter.com/excel-discussion-misc-queries/99894-declaring-variables.html)

freekrill

Declaring variables
 

Hi,

I want to declare a variable which can be either an integer or null.
What do I put in the dim x as ... statement?

Thanks for your help

free


--
freekrill
------------------------------------------------------------------------
freekrill's Profile: http://www.excelforum.com/member.php...fo&userid=7561
View this thread: http://www.excelforum.com/showthread...hreadid=562547


Chip Pearson

Declaring variables
 
Use a Variant type variable.


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

"freekrill"
wrote in
message
...

Hi,

I want to declare a variable which can be either an integer or
null.
What do I put in the dim x as ... statement?

Thanks for your help

free


--
freekrill
------------------------------------------------------------------------
freekrill's Profile:
http://www.excelforum.com/member.php...fo&userid=7561
View this thread:
http://www.excelforum.com/showthread...hreadid=562547




freekrill

Declaring variables
 

Thanks Chip,

I have tried that, but when I then try to sum two of the inputs, it
concatenates instead. A simple example of what I have tried is below.
Thanks for any comments

free

Sub test ()

Dim a as Variant
Dim b as Variant

a = InputBox("Enter A")
If a = "" Then a = 0
b = InputBox("Enter B")
If b = "" Then b = 0
c = a + b
Range("A1").Value = c

End Sub

When I run the macro and enter, say, 1 for A and 2 for B, I get the
value 12 in "A1", rather than 3 which is what I want.


--
freekrill
------------------------------------------------------------------------
freekrill's Profile: http://www.excelforum.com/member.php...fo&userid=7561
View this thread: http://www.excelforum.com/showthread...hreadid=562547



All times are GMT +1. The time now is 02:59 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com