Basic VBA Questions (Integer)
Sub CommandButton1_Click()
Dim x As Integer
x = 6
Range("A1").Value = x
End Sub
This means that you assign X as Integer, and you say the x equals to 6.
And then you put the value x(=6) in cell "A1".
Sub CommandButton1_Click()
Dim x As Double
x = 6
Range("A1").Value = x
End Sub
But why does the second one work also?
excel vba excel-vba
|
show 7 more comments
Sub CommandButton1_Click()
Dim x As Integer
x = 6
Range("A1").Value = x
End Sub
This means that you assign X as Integer, and you say the x equals to 6.
And then you put the value x(=6) in cell "A1".
Sub CommandButton1_Click()
Dim x As Double
x = 6
Range("A1").Value = x
End Sub
But why does the second one work also?
excel vba excel-vba
1
Why wouldn't it? An integer is still a double.
– SJR
Nov 26 '18 at 18:34
1
No? Its like a dog is an animal but an animal isn't a dog.
– Riley Carney
Nov 26 '18 at 18:45
1
Because VBA manages some silent type conversions to make your life 'easier'. If you wish to know what type was actually passed add the line debug.print TypeName(Range("A1").value)
– Freeflow
Nov 26 '18 at 18:47
1
Why do you think it should not work?
– Ken White
Nov 26 '18 at 18:47
1
@RileyCarney - unless it's a cat-dog hybrid. A cog?
– SJR
Nov 26 '18 at 19:54
|
show 7 more comments
Sub CommandButton1_Click()
Dim x As Integer
x = 6
Range("A1").Value = x
End Sub
This means that you assign X as Integer, and you say the x equals to 6.
And then you put the value x(=6) in cell "A1".
Sub CommandButton1_Click()
Dim x As Double
x = 6
Range("A1").Value = x
End Sub
But why does the second one work also?
excel vba excel-vba
Sub CommandButton1_Click()
Dim x As Integer
x = 6
Range("A1").Value = x
End Sub
This means that you assign X as Integer, and you say the x equals to 6.
And then you put the value x(=6) in cell "A1".
Sub CommandButton1_Click()
Dim x As Double
x = 6
Range("A1").Value = x
End Sub
But why does the second one work also?
excel vba excel-vba
excel vba excel-vba
edited Nov 27 '18 at 8:07
Pᴇʜ
22.8k62850
22.8k62850
asked Nov 26 '18 at 18:32
Im Hun JungIm Hun Jung
84
84
1
Why wouldn't it? An integer is still a double.
– SJR
Nov 26 '18 at 18:34
1
No? Its like a dog is an animal but an animal isn't a dog.
– Riley Carney
Nov 26 '18 at 18:45
1
Because VBA manages some silent type conversions to make your life 'easier'. If you wish to know what type was actually passed add the line debug.print TypeName(Range("A1").value)
– Freeflow
Nov 26 '18 at 18:47
1
Why do you think it should not work?
– Ken White
Nov 26 '18 at 18:47
1
@RileyCarney - unless it's a cat-dog hybrid. A cog?
– SJR
Nov 26 '18 at 19:54
|
show 7 more comments
1
Why wouldn't it? An integer is still a double.
– SJR
Nov 26 '18 at 18:34
1
No? Its like a dog is an animal but an animal isn't a dog.
– Riley Carney
Nov 26 '18 at 18:45
1
Because VBA manages some silent type conversions to make your life 'easier'. If you wish to know what type was actually passed add the line debug.print TypeName(Range("A1").value)
– Freeflow
Nov 26 '18 at 18:47
1
Why do you think it should not work?
– Ken White
Nov 26 '18 at 18:47
1
@RileyCarney - unless it's a cat-dog hybrid. A cog?
– SJR
Nov 26 '18 at 19:54
1
1
Why wouldn't it? An integer is still a double.
– SJR
Nov 26 '18 at 18:34
Why wouldn't it? An integer is still a double.
– SJR
Nov 26 '18 at 18:34
1
1
No? Its like a dog is an animal but an animal isn't a dog.
– Riley Carney
Nov 26 '18 at 18:45
No? Its like a dog is an animal but an animal isn't a dog.
– Riley Carney
Nov 26 '18 at 18:45
1
1
Because VBA manages some silent type conversions to make your life 'easier'. If you wish to know what type was actually passed add the line debug.print TypeName(Range("A1").value)
– Freeflow
Nov 26 '18 at 18:47
Because VBA manages some silent type conversions to make your life 'easier'. If you wish to know what type was actually passed add the line debug.print TypeName(Range("A1").value)
– Freeflow
Nov 26 '18 at 18:47
1
1
Why do you think it should not work?
– Ken White
Nov 26 '18 at 18:47
Why do you think it should not work?
– Ken White
Nov 26 '18 at 18:47
1
1
@RileyCarney - unless it's a cat-dog hybrid. A cog?
– SJR
Nov 26 '18 at 19:54
@RileyCarney - unless it's a cat-dog hybrid. A cog?
– SJR
Nov 26 '18 at 19:54
|
show 7 more comments
2 Answers
2
active
oldest
votes
TL;DR: Type conversions.
Range.Value is a Variant, which is a special data type that stores a pointer to a value, along with a description of the data type: that's how a cell can hold a Double, a String, a Boolean, or an Error value.
Anything deeper than that is irrelevant to the question at hand.
Integer is a 16-bit signed integer type that can easily fit into a Double, which is much larger than 16 bits. If you followed the .Value assignment with this:
Debug.Print TypeName(Range("A1").Value)
You would get Double in the debug output.
Somewhere in the implementation of the Range.Value property, a validation of the supplied value is performed, and if the value is acceptable, it's stored internally in the appropriate data type. If the value isn't of an acceptable data type, error 1004 is thrown. Integer being a fine numeric value, all is good.
The exact same thing happens in the second snippet: Double being a fine numeric value, all is good. And since any numeric value taken from a cell is a Variant/Double, we can reasonably infer that somewhere in the internal guts of Range, numeric values are stored as Double - although, that could very well just be an implementation detail of how the getter of the Range.Value property is implemented.
VBA was designed to work with a specific set of data types, and the type libraries of VBA host applications (e.g. Excel) were designed to accept these data types. Hence, you would have to work pretty hard to give Range.Value a value it can't deal with, using VBA code.
But before the value even gets to the Range.Value property, an implicit type conversion has aready occurred in the second snippet.
Dim x As Integer
x = 6
Here 6 is an integer literal. When VBA executes the x = 6 instruction, that 6 already has a data type - and that data type is Integer.
Dim x As Double
x = 6
Here 6 is also an integer literal, but it's assigned to a Double, which isn't the same type: an implicit type conversion occurs, and x happily takes an Integer value - because the conversion is widening.
Now consider:
Dim x As Double
x = 6#
Here 6# uses a type hint. Debug.Print TypeName(6#) prints Double: that 6# is a Double literal - no type conversion occurs here. But it's ugly.
Dim x As Double
x = CDbl(6)
Now the widening type conversion is explicit.
When an implicit conversion is narrowing instead, and the value can't fit into the needed data type...
Dim x As Integer
x = 32768 '<~ that's a Long integer literal: doesn't fit the 16 bits of an Integer
...then runtime error 6 ("Overflow") is thrown. Since every VBA numeric data type can safely be converted to a Double, every numeric value that can be supplied by VBA code, can be assigned to Range.Value.
Thanks for the nice explanation you put here! It is really helpful
– Im Hun Jung
Nov 29 '18 at 10:29
add a comment |
Internally Excel does not use an Integer. Cells are one of four types:
- Double precision floating point (all numbers including integers,
currency, dates times etc) - String
- Boolean
- Error
Note this means all numbers are doubles.
See these references:
Data types used by Excel - "All worksheet numbers in Excel are stored as doubles"
Excel VBA internal data format and memory storage
The "Data types used by Excel" link directly contradicts the statement "Internally Excel does not use an Integer", and the "Excel VBA internal data format and memory storage" link is dubious at best (in that it contains some provably false statements) - it also ignores casting at the level of COM objects (Range.Value2is a property that doesn't necessarily represent how Excel stores data internally). I'd go as far as to say that it's simply wrong.
– Comintern
Nov 26 '18 at 18:53
Excel as an application handles more datatypes than the fundamental four, but when it assigns to a worksheet cell such as in the example above, it silently converts to one of the four. With regards to Value2, there's a reason Excel has Value, Value2 and Text ...
– Alan
Nov 26 '18 at 18:57
And you're substantiating this how? If everything internally in Excel was stored as a float, you'd get floating point errors all over the place. With regards toValue2,Value, andText, those are interfaces - the assumption that they point directly at Excel's internal storage is naïve at best.
– Comintern
Nov 26 '18 at 19:01
1
Here it says everything is stored as text.
– Storax
Nov 26 '18 at 19:06
@Storax The answer in that post refers to how Excel writes out the file as OpenXML, not how it assigns the values.
– Alan
Nov 26 '18 at 19:14
|
show 4 more comments
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53487065%2fbasic-vba-questions-integer%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
TL;DR: Type conversions.
Range.Value is a Variant, which is a special data type that stores a pointer to a value, along with a description of the data type: that's how a cell can hold a Double, a String, a Boolean, or an Error value.
Anything deeper than that is irrelevant to the question at hand.
Integer is a 16-bit signed integer type that can easily fit into a Double, which is much larger than 16 bits. If you followed the .Value assignment with this:
Debug.Print TypeName(Range("A1").Value)
You would get Double in the debug output.
Somewhere in the implementation of the Range.Value property, a validation of the supplied value is performed, and if the value is acceptable, it's stored internally in the appropriate data type. If the value isn't of an acceptable data type, error 1004 is thrown. Integer being a fine numeric value, all is good.
The exact same thing happens in the second snippet: Double being a fine numeric value, all is good. And since any numeric value taken from a cell is a Variant/Double, we can reasonably infer that somewhere in the internal guts of Range, numeric values are stored as Double - although, that could very well just be an implementation detail of how the getter of the Range.Value property is implemented.
VBA was designed to work with a specific set of data types, and the type libraries of VBA host applications (e.g. Excel) were designed to accept these data types. Hence, you would have to work pretty hard to give Range.Value a value it can't deal with, using VBA code.
But before the value even gets to the Range.Value property, an implicit type conversion has aready occurred in the second snippet.
Dim x As Integer
x = 6
Here 6 is an integer literal. When VBA executes the x = 6 instruction, that 6 already has a data type - and that data type is Integer.
Dim x As Double
x = 6
Here 6 is also an integer literal, but it's assigned to a Double, which isn't the same type: an implicit type conversion occurs, and x happily takes an Integer value - because the conversion is widening.
Now consider:
Dim x As Double
x = 6#
Here 6# uses a type hint. Debug.Print TypeName(6#) prints Double: that 6# is a Double literal - no type conversion occurs here. But it's ugly.
Dim x As Double
x = CDbl(6)
Now the widening type conversion is explicit.
When an implicit conversion is narrowing instead, and the value can't fit into the needed data type...
Dim x As Integer
x = 32768 '<~ that's a Long integer literal: doesn't fit the 16 bits of an Integer
...then runtime error 6 ("Overflow") is thrown. Since every VBA numeric data type can safely be converted to a Double, every numeric value that can be supplied by VBA code, can be assigned to Range.Value.
Thanks for the nice explanation you put here! It is really helpful
– Im Hun Jung
Nov 29 '18 at 10:29
add a comment |
TL;DR: Type conversions.
Range.Value is a Variant, which is a special data type that stores a pointer to a value, along with a description of the data type: that's how a cell can hold a Double, a String, a Boolean, or an Error value.
Anything deeper than that is irrelevant to the question at hand.
Integer is a 16-bit signed integer type that can easily fit into a Double, which is much larger than 16 bits. If you followed the .Value assignment with this:
Debug.Print TypeName(Range("A1").Value)
You would get Double in the debug output.
Somewhere in the implementation of the Range.Value property, a validation of the supplied value is performed, and if the value is acceptable, it's stored internally in the appropriate data type. If the value isn't of an acceptable data type, error 1004 is thrown. Integer being a fine numeric value, all is good.
The exact same thing happens in the second snippet: Double being a fine numeric value, all is good. And since any numeric value taken from a cell is a Variant/Double, we can reasonably infer that somewhere in the internal guts of Range, numeric values are stored as Double - although, that could very well just be an implementation detail of how the getter of the Range.Value property is implemented.
VBA was designed to work with a specific set of data types, and the type libraries of VBA host applications (e.g. Excel) were designed to accept these data types. Hence, you would have to work pretty hard to give Range.Value a value it can't deal with, using VBA code.
But before the value even gets to the Range.Value property, an implicit type conversion has aready occurred in the second snippet.
Dim x As Integer
x = 6
Here 6 is an integer literal. When VBA executes the x = 6 instruction, that 6 already has a data type - and that data type is Integer.
Dim x As Double
x = 6
Here 6 is also an integer literal, but it's assigned to a Double, which isn't the same type: an implicit type conversion occurs, and x happily takes an Integer value - because the conversion is widening.
Now consider:
Dim x As Double
x = 6#
Here 6# uses a type hint. Debug.Print TypeName(6#) prints Double: that 6# is a Double literal - no type conversion occurs here. But it's ugly.
Dim x As Double
x = CDbl(6)
Now the widening type conversion is explicit.
When an implicit conversion is narrowing instead, and the value can't fit into the needed data type...
Dim x As Integer
x = 32768 '<~ that's a Long integer literal: doesn't fit the 16 bits of an Integer
...then runtime error 6 ("Overflow") is thrown. Since every VBA numeric data type can safely be converted to a Double, every numeric value that can be supplied by VBA code, can be assigned to Range.Value.
Thanks for the nice explanation you put here! It is really helpful
– Im Hun Jung
Nov 29 '18 at 10:29
add a comment |
TL;DR: Type conversions.
Range.Value is a Variant, which is a special data type that stores a pointer to a value, along with a description of the data type: that's how a cell can hold a Double, a String, a Boolean, or an Error value.
Anything deeper than that is irrelevant to the question at hand.
Integer is a 16-bit signed integer type that can easily fit into a Double, which is much larger than 16 bits. If you followed the .Value assignment with this:
Debug.Print TypeName(Range("A1").Value)
You would get Double in the debug output.
Somewhere in the implementation of the Range.Value property, a validation of the supplied value is performed, and if the value is acceptable, it's stored internally in the appropriate data type. If the value isn't of an acceptable data type, error 1004 is thrown. Integer being a fine numeric value, all is good.
The exact same thing happens in the second snippet: Double being a fine numeric value, all is good. And since any numeric value taken from a cell is a Variant/Double, we can reasonably infer that somewhere in the internal guts of Range, numeric values are stored as Double - although, that could very well just be an implementation detail of how the getter of the Range.Value property is implemented.
VBA was designed to work with a specific set of data types, and the type libraries of VBA host applications (e.g. Excel) were designed to accept these data types. Hence, you would have to work pretty hard to give Range.Value a value it can't deal with, using VBA code.
But before the value even gets to the Range.Value property, an implicit type conversion has aready occurred in the second snippet.
Dim x As Integer
x = 6
Here 6 is an integer literal. When VBA executes the x = 6 instruction, that 6 already has a data type - and that data type is Integer.
Dim x As Double
x = 6
Here 6 is also an integer literal, but it's assigned to a Double, which isn't the same type: an implicit type conversion occurs, and x happily takes an Integer value - because the conversion is widening.
Now consider:
Dim x As Double
x = 6#
Here 6# uses a type hint. Debug.Print TypeName(6#) prints Double: that 6# is a Double literal - no type conversion occurs here. But it's ugly.
Dim x As Double
x = CDbl(6)
Now the widening type conversion is explicit.
When an implicit conversion is narrowing instead, and the value can't fit into the needed data type...
Dim x As Integer
x = 32768 '<~ that's a Long integer literal: doesn't fit the 16 bits of an Integer
...then runtime error 6 ("Overflow") is thrown. Since every VBA numeric data type can safely be converted to a Double, every numeric value that can be supplied by VBA code, can be assigned to Range.Value.
TL;DR: Type conversions.
Range.Value is a Variant, which is a special data type that stores a pointer to a value, along with a description of the data type: that's how a cell can hold a Double, a String, a Boolean, or an Error value.
Anything deeper than that is irrelevant to the question at hand.
Integer is a 16-bit signed integer type that can easily fit into a Double, which is much larger than 16 bits. If you followed the .Value assignment with this:
Debug.Print TypeName(Range("A1").Value)
You would get Double in the debug output.
Somewhere in the implementation of the Range.Value property, a validation of the supplied value is performed, and if the value is acceptable, it's stored internally in the appropriate data type. If the value isn't of an acceptable data type, error 1004 is thrown. Integer being a fine numeric value, all is good.
The exact same thing happens in the second snippet: Double being a fine numeric value, all is good. And since any numeric value taken from a cell is a Variant/Double, we can reasonably infer that somewhere in the internal guts of Range, numeric values are stored as Double - although, that could very well just be an implementation detail of how the getter of the Range.Value property is implemented.
VBA was designed to work with a specific set of data types, and the type libraries of VBA host applications (e.g. Excel) were designed to accept these data types. Hence, you would have to work pretty hard to give Range.Value a value it can't deal with, using VBA code.
But before the value even gets to the Range.Value property, an implicit type conversion has aready occurred in the second snippet.
Dim x As Integer
x = 6
Here 6 is an integer literal. When VBA executes the x = 6 instruction, that 6 already has a data type - and that data type is Integer.
Dim x As Double
x = 6
Here 6 is also an integer literal, but it's assigned to a Double, which isn't the same type: an implicit type conversion occurs, and x happily takes an Integer value - because the conversion is widening.
Now consider:
Dim x As Double
x = 6#
Here 6# uses a type hint. Debug.Print TypeName(6#) prints Double: that 6# is a Double literal - no type conversion occurs here. But it's ugly.
Dim x As Double
x = CDbl(6)
Now the widening type conversion is explicit.
When an implicit conversion is narrowing instead, and the value can't fit into the needed data type...
Dim x As Integer
x = 32768 '<~ that's a Long integer literal: doesn't fit the 16 bits of an Integer
...then runtime error 6 ("Overflow") is thrown. Since every VBA numeric data type can safely be converted to a Double, every numeric value that can be supplied by VBA code, can be assigned to Range.Value.
edited Nov 26 '18 at 20:31
answered Nov 26 '18 at 20:25
Mathieu GuindonMathieu Guindon
43.3k767147
43.3k767147
Thanks for the nice explanation you put here! It is really helpful
– Im Hun Jung
Nov 29 '18 at 10:29
add a comment |
Thanks for the nice explanation you put here! It is really helpful
– Im Hun Jung
Nov 29 '18 at 10:29
Thanks for the nice explanation you put here! It is really helpful
– Im Hun Jung
Nov 29 '18 at 10:29
Thanks for the nice explanation you put here! It is really helpful
– Im Hun Jung
Nov 29 '18 at 10:29
add a comment |
Internally Excel does not use an Integer. Cells are one of four types:
- Double precision floating point (all numbers including integers,
currency, dates times etc) - String
- Boolean
- Error
Note this means all numbers are doubles.
See these references:
Data types used by Excel - "All worksheet numbers in Excel are stored as doubles"
Excel VBA internal data format and memory storage
The "Data types used by Excel" link directly contradicts the statement "Internally Excel does not use an Integer", and the "Excel VBA internal data format and memory storage" link is dubious at best (in that it contains some provably false statements) - it also ignores casting at the level of COM objects (Range.Value2is a property that doesn't necessarily represent how Excel stores data internally). I'd go as far as to say that it's simply wrong.
– Comintern
Nov 26 '18 at 18:53
Excel as an application handles more datatypes than the fundamental four, but when it assigns to a worksheet cell such as in the example above, it silently converts to one of the four. With regards to Value2, there's a reason Excel has Value, Value2 and Text ...
– Alan
Nov 26 '18 at 18:57
And you're substantiating this how? If everything internally in Excel was stored as a float, you'd get floating point errors all over the place. With regards toValue2,Value, andText, those are interfaces - the assumption that they point directly at Excel's internal storage is naïve at best.
– Comintern
Nov 26 '18 at 19:01
1
Here it says everything is stored as text.
– Storax
Nov 26 '18 at 19:06
@Storax The answer in that post refers to how Excel writes out the file as OpenXML, not how it assigns the values.
– Alan
Nov 26 '18 at 19:14
|
show 4 more comments
Internally Excel does not use an Integer. Cells are one of four types:
- Double precision floating point (all numbers including integers,
currency, dates times etc) - String
- Boolean
- Error
Note this means all numbers are doubles.
See these references:
Data types used by Excel - "All worksheet numbers in Excel are stored as doubles"
Excel VBA internal data format and memory storage
The "Data types used by Excel" link directly contradicts the statement "Internally Excel does not use an Integer", and the "Excel VBA internal data format and memory storage" link is dubious at best (in that it contains some provably false statements) - it also ignores casting at the level of COM objects (Range.Value2is a property that doesn't necessarily represent how Excel stores data internally). I'd go as far as to say that it's simply wrong.
– Comintern
Nov 26 '18 at 18:53
Excel as an application handles more datatypes than the fundamental four, but when it assigns to a worksheet cell such as in the example above, it silently converts to one of the four. With regards to Value2, there's a reason Excel has Value, Value2 and Text ...
– Alan
Nov 26 '18 at 18:57
And you're substantiating this how? If everything internally in Excel was stored as a float, you'd get floating point errors all over the place. With regards toValue2,Value, andText, those are interfaces - the assumption that they point directly at Excel's internal storage is naïve at best.
– Comintern
Nov 26 '18 at 19:01
1
Here it says everything is stored as text.
– Storax
Nov 26 '18 at 19:06
@Storax The answer in that post refers to how Excel writes out the file as OpenXML, not how it assigns the values.
– Alan
Nov 26 '18 at 19:14
|
show 4 more comments
Internally Excel does not use an Integer. Cells are one of four types:
- Double precision floating point (all numbers including integers,
currency, dates times etc) - String
- Boolean
- Error
Note this means all numbers are doubles.
See these references:
Data types used by Excel - "All worksheet numbers in Excel are stored as doubles"
Excel VBA internal data format and memory storage
Internally Excel does not use an Integer. Cells are one of four types:
- Double precision floating point (all numbers including integers,
currency, dates times etc) - String
- Boolean
- Error
Note this means all numbers are doubles.
See these references:
Data types used by Excel - "All worksheet numbers in Excel are stored as doubles"
Excel VBA internal data format and memory storage
answered Nov 26 '18 at 18:47
AlanAlan
1,2992415
1,2992415
The "Data types used by Excel" link directly contradicts the statement "Internally Excel does not use an Integer", and the "Excel VBA internal data format and memory storage" link is dubious at best (in that it contains some provably false statements) - it also ignores casting at the level of COM objects (Range.Value2is a property that doesn't necessarily represent how Excel stores data internally). I'd go as far as to say that it's simply wrong.
– Comintern
Nov 26 '18 at 18:53
Excel as an application handles more datatypes than the fundamental four, but when it assigns to a worksheet cell such as in the example above, it silently converts to one of the four. With regards to Value2, there's a reason Excel has Value, Value2 and Text ...
– Alan
Nov 26 '18 at 18:57
And you're substantiating this how? If everything internally in Excel was stored as a float, you'd get floating point errors all over the place. With regards toValue2,Value, andText, those are interfaces - the assumption that they point directly at Excel's internal storage is naïve at best.
– Comintern
Nov 26 '18 at 19:01
1
Here it says everything is stored as text.
– Storax
Nov 26 '18 at 19:06
@Storax The answer in that post refers to how Excel writes out the file as OpenXML, not how it assigns the values.
– Alan
Nov 26 '18 at 19:14
|
show 4 more comments
The "Data types used by Excel" link directly contradicts the statement "Internally Excel does not use an Integer", and the "Excel VBA internal data format and memory storage" link is dubious at best (in that it contains some provably false statements) - it also ignores casting at the level of COM objects (Range.Value2is a property that doesn't necessarily represent how Excel stores data internally). I'd go as far as to say that it's simply wrong.
– Comintern
Nov 26 '18 at 18:53
Excel as an application handles more datatypes than the fundamental four, but when it assigns to a worksheet cell such as in the example above, it silently converts to one of the four. With regards to Value2, there's a reason Excel has Value, Value2 and Text ...
– Alan
Nov 26 '18 at 18:57
And you're substantiating this how? If everything internally in Excel was stored as a float, you'd get floating point errors all over the place. With regards toValue2,Value, andText, those are interfaces - the assumption that they point directly at Excel's internal storage is naïve at best.
– Comintern
Nov 26 '18 at 19:01
1
Here it says everything is stored as text.
– Storax
Nov 26 '18 at 19:06
@Storax The answer in that post refers to how Excel writes out the file as OpenXML, not how it assigns the values.
– Alan
Nov 26 '18 at 19:14
The "Data types used by Excel" link directly contradicts the statement "Internally Excel does not use an Integer", and the "Excel VBA internal data format and memory storage" link is dubious at best (in that it contains some provably false statements) - it also ignores casting at the level of COM objects (
Range.Value2 is a property that doesn't necessarily represent how Excel stores data internally). I'd go as far as to say that it's simply wrong.– Comintern
Nov 26 '18 at 18:53
The "Data types used by Excel" link directly contradicts the statement "Internally Excel does not use an Integer", and the "Excel VBA internal data format and memory storage" link is dubious at best (in that it contains some provably false statements) - it also ignores casting at the level of COM objects (
Range.Value2 is a property that doesn't necessarily represent how Excel stores data internally). I'd go as far as to say that it's simply wrong.– Comintern
Nov 26 '18 at 18:53
Excel as an application handles more datatypes than the fundamental four, but when it assigns to a worksheet cell such as in the example above, it silently converts to one of the four. With regards to Value2, there's a reason Excel has Value, Value2 and Text ...
– Alan
Nov 26 '18 at 18:57
Excel as an application handles more datatypes than the fundamental four, but when it assigns to a worksheet cell such as in the example above, it silently converts to one of the four. With regards to Value2, there's a reason Excel has Value, Value2 and Text ...
– Alan
Nov 26 '18 at 18:57
And you're substantiating this how? If everything internally in Excel was stored as a float, you'd get floating point errors all over the place. With regards to
Value2, Value, and Text, those are interfaces - the assumption that they point directly at Excel's internal storage is naïve at best.– Comintern
Nov 26 '18 at 19:01
And you're substantiating this how? If everything internally in Excel was stored as a float, you'd get floating point errors all over the place. With regards to
Value2, Value, and Text, those are interfaces - the assumption that they point directly at Excel's internal storage is naïve at best.– Comintern
Nov 26 '18 at 19:01
1
1
Here it says everything is stored as text.
– Storax
Nov 26 '18 at 19:06
Here it says everything is stored as text.
– Storax
Nov 26 '18 at 19:06
@Storax The answer in that post refers to how Excel writes out the file as OpenXML, not how it assigns the values.
– Alan
Nov 26 '18 at 19:14
@Storax The answer in that post refers to how Excel writes out the file as OpenXML, not how it assigns the values.
– Alan
Nov 26 '18 at 19:14
|
show 4 more comments
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53487065%2fbasic-vba-questions-integer%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
1
Why wouldn't it? An integer is still a double.
– SJR
Nov 26 '18 at 18:34
1
No? Its like a dog is an animal but an animal isn't a dog.
– Riley Carney
Nov 26 '18 at 18:45
1
Because VBA manages some silent type conversions to make your life 'easier'. If you wish to know what type was actually passed add the line debug.print TypeName(Range("A1").value)
– Freeflow
Nov 26 '18 at 18:47
1
Why do you think it should not work?
– Ken White
Nov 26 '18 at 18:47
1
@RileyCarney - unless it's a cat-dog hybrid. A cog?
– SJR
Nov 26 '18 at 19:54