Code:
Sub RangeObjectDefaultPropertiesCell() ' https://www.excelfox.com/forum/showthread.php/2914-Tests-and-Notes-on-Range-objects-in-Excel-Cell?p=22092&viewfull=1#post22092 https://www.excelfox.com/forum/showthread.php/2345-Appendix-Thread-(-Codes-for-other-Threads-HTML-Tables-etc-)?p=21979&viewfull=1#post21979
Rem 0 ' Test data range
Dim Ws12 As Worksheet: Set Ws12 = ThisWorkbook.Worksheets.Item("Sheet1 (2)")
Ws12.Range("A75:E75").Clear ' .Clear to get rid of all valiues and any formats
' LHS In the classic, (pseudo) code line Range2.Value = Range1.Value I don't experience any difference with the LHS being Range2.Value = or Range2 = Watch : : Ws12.Range("A69").Value : "44" : Variant/String : Sheet2.RangeObjectDefaultPropertiesCell
Let Ws12.Range("A69").Value = Split("44") ' ' Gives number stored as Text Thing https://i.postimg.cc/XYrvmWdH/Number-stored-as-Text-Thing.jpg Number held as text thing
Let Ws12.Range("A69").Value = Split("44") ' Watch : - : Split("44") : : Variant/String(0 to 0) : Sheet2.RangeObjectDefaultPropertiesCell
' : Split("44")(0) : "44" : String : Sheet2.RangeObjectDefaultPropertiesCell
Let Ws12.Range("A69").Value = Split("44") ' Watch : : Ws12.Range("A69").Value : "44" : Variant/String : Sheet2.RangeObjectDefaultPropertiesCell
Let Ws12.Range("A69") = Split("44") ' Watch : - : Ws12.Range("A69") : "44" : Object/Range : Sheet2.RangeObjectDefaultPropertiesCell
Let Ws12.Range("D69") = Split("44")(0) ' This does not give the Number stored as Text Thing https://i.postimg.cc/XYrvmWdH/Number-stored-as-Text-Thing.jpg Number held as text thing Watch : : Ws12.Range("D69").Value : 55 : Variant/Double : Sheet2.RangeObjectDefaultPropertiesCell
Let Ws12.Range("D69") = Split("44")(0) ' Watch : : Split("44")(0) : "44" : Variant/String : Sheet2.RangeObjectDefaultPropertiesCell
Let Ws12.Range("D69") = Split("44")(0) ' Watch : + : Ws12.Range("D69") : 44 : Object/Range : Sheet2.RangeObjectDefaultPropertiesCell
Let Ws12.Range("D69").Value = 55 ' This does not give the Number stored as Text Thing https://i.postimg.cc/XYrvmWdH/Number-stored-as-Text-Thing.jpg Number held as text thing
Let Ws12.Range("D69").Value = 55 ' Watch : : Ws12.Range("D69").Value : 55 : Variant/Double : Sheet2.RangeObjectDefaultPropertiesCell
Let Ws12.Range("D69") = 55 ' Watch : + : Ws12.Range("D69") : 55 : Object/Range : Sheet2.RangeObjectDefaultPropertiesCell
Let Ws12.Range("C69").Value = "44" ' This does not give the Number stored as Text Thing https://i.postimg.cc/XYrvmWdH/Number-stored-as-Text-Thing.jpg Number held as text thing
Let Ws12.Range("C69").Value = "44" ' Watch : : "44" : "44" : String : Sheet2.RangeObjectDefaultPropertiesCell
Let Ws12.Range("C69").Value = "44" ' Watch : : Range("C69").Value : 44 : Variant/Double : Sheet2.RangeObjectDefaultPropertiesCell
Let Ws12.Range("C69") = "44" ' Watch : - : Ws12.Range("C69") : 44 : Object/Range : Sheet2.RangeObjectDefaultPropertiesCell
' : Value2 : 44 : Variant/Double : Sheet2.RangeObjectDefaultPropertiesCell
' ' https://i.postimg.cc/DyBC0ZnB/Written-Properties.jpg
' ' https://i.postimg.cc/Ghc7bYw4/Written-Properties.jpg
' ' https://i.postimg.cc/L85x1psR/Written-Properties.jpg
' ' https://i.postimg.cc/ryGZ6jb6/Written-Property-Value.jpg
' "values" The word values often refers generally to things in the cell numbers text and the formatting that can be done with just numbers and text. In other words, these following all have the same effect.
Range("A69").Clear
Let Ws12.Range("A69").Value = Split("44"): Range("A69").Clear
Let Ws12.Range("A69") = Split("44"): Range("A69").Clear
Let Ws12.Range("A69").FormulaR1C1Local = Split("44"): Range("A69").Clear
Let Ws12.Range("A69").Formula = Split("44")
' Perhaps anytime we use any of these Properties, we default to just Range =
Rem 1 Variable type considerations
Dim Rng As Range
Set Rng = Ws12.Range("A69") ' Watch : + : Rng : "44" : Range/Range : Sheet2.RangeObjectDefaultPropertiesCells
Debug.Print VarTyp(VarType(Rng)) ' String What is this String? Could it be this https://i.postimg.cc/0NWjBNHB/Number-stored-as-Text-Thing-Could-it-be-this.jpg , the "written property value" https://i.postimg.cc/ryGZ6jb6/Written-Property-Value.jpg
Dim vTemp As Variant, Str As String
Let vTemp = Rng ' Watch : : vTemp : "44" : Variant/String : Sheet2.RangeObjectDefaultPropertiesCells
Let Str = Rng ' Watch : : Str : "44" : String : Sheet2.RangeObjectDefaultPropertiesCells
' RHS
Rem 2
Let Ws12.Range("A75") = Ws12.Range("A69").Value ' https://i.postimg.cc/bYWyfPc6/Does-not-give-Number-held-as-Text-thing.jpg
Let Ws12.Range("A75") = Rng.Value ' These two lines do not result in the Number held as Text thing
' Use .Value and we put a value in the cell, like if we humans write stuff in a cell, Excel will decide if its a number or text regardless of any Number as text thing
' Actually we are doing this, The optional argument tends to support the idea that on the RHS, the .Value is a method , ( although note its only been available since Excel 2007 )
Let Ws12.Range("A75") = Rng.Value(RangeValueDataType:=xlRangeValueDefault) ' RangeValueDataType:=https://learn.microsoft.com/en-us/office/vba/api/excel.range.value https://learn.microsoft.com/en-us/office/vba/api/excel.xlrangevaluedatatype https://fastexcel.wordpress.com/2017/03/13/excel-range-valuevaluetype-what-is-this-parameter/
' we have other options, for example
Ws12.Range("B75") = Rng.Value(RangeValueDataType:=xlRangeValueXMLSpreadsheet): Let Ws12.Range("B75").WrapText = False
' https://i.postimg.cc/NF3B66kh/Value-XMLSpreadsheet.jpg
' Now it gets intersting,
Let Ws12.Range("C75") = Rng ' this DOES the Number stored as Text Thing https://i.postimg.cc/hvzKQyxb/Number-held-as-string-thing.jpg https://i.postimg.cc/XYrvmWdH/Number-stored-as-Text-Thing.jpg Number held as text thing
' If you don't use .Value a range object is put in, something we human's can't do , and any Number as text stuff will be preserved
' ' Or
' This might be the "thing" that we sometimes get for various objects, when we assign that object to a string type variable. For some reason it works then differently, rather than "writing" into the cell in similar way that we might do, it does it in some other way such that the actual text is put in, and so we appear to get the Number stored as text Thing warning thing preserved
' https://i.postimg.cc/Xq1HsdJL/Cell-A69.jpg
Rem 3
'3a) I expect this is not defaulting to .Value Rather, VBA may be conveniently obligingly coercing the range object being returned from the RHS. saying that in a different way, if VBA gets a range object where it is not expecting one, then it might be wired to do something, such as look for an appropriate property/method to suit
Dim Var As Variant
Let Var = Rng ' Watch : : Var : "44" : Variant/String : Sheet2.RangeObjectDefaultPropertiesCells
Let Var = Ws12.Range("A75") ' Watch : : Var : 44 : Variant/Double : Sheet2.RangeObjectDefaultPropertiesCells
'3b) Although the results are the same here, I think it is working differently.
Let Var = Rng.Value ' Watch : : Var : "44" : Variant/String : Sheet2.RangeObjectDefaultPropertiesCells
Let Var = Ws12.Range("A75").Value ' Watch : : Var : 44 : Variant/Double : Sheet2.RangeObjectDefaultPropertiesCells
'3b(i) we are actually doing this https://learn.microsoft.com/en-us/office/vba/api/excel.range.value https://learn.microsoft.com/en-us/office/vba/api/excel.xlrangevaluedatatype
Let Var = Rng.Value(RangeValueDataType:=xlRangeValueDefault) ' Watch : : Var : "44" : Variant/String : Sheet2.RangeObjectDefaultPropertiesCells
''3b(ii) but we could also do this
Let Var = Rng.Value(RangeValueDataType:=xlRangeValueXMLSpreadsheet) ' Watch : : Var : "
'
'
' xmlns: o = "urn:schemas-microsoft-com:office:office"
' ... etc
'
' Let Var = Rng2.Value(RangeValueDataType:=xlRangeValueXMLSpreadsheet) ' Watch : : Var : "
'
'
' xmlns: o = "urn:schemas-microsoft-com:office:office"
' ... etc
End Sub
https://www.youtube.com/channel/UCnxwq2aGJRbjOo_MO54oaHA
https://www.youtube.com/channel/UCnxwq2aGJRbjOo_MO54oaHA
Bookmarks