Excel - alignment of numeric values in cells?

User avatar
ChrisGreaves
PlutoniumLounger
Posts: 15628
Joined: 24 Jan 2010, 23:23
Location: brings.slot.perky

Excel - alignment of numeric values in cells?

Post by ChrisGreaves »

Untitled.png
The difference between row 6 and row 8 is that:-
up to and including row 6 I keyed in data by hand, and
after and including row 8 I keyed the data into a crude VBA form using the range.VALUE

Code: Select all

If frmVesey.cmdOK.Tag = "Y" Then
    ActiveCell.Offset(0, 0).Value = .tbPage
    ActiveCell.Offset(0, 1).Value = UCase(.tbLetter)
    ActiveCell.Offset(0, 2).Value = .tbOrderNo
    ActiveCell.Offset(0, 3).Value = .tbQuant
    ActiveCell.Offset(0, 4).Value = .tbCost
    ActiveCell.Offset(0, 5).Value = .tbCost / .tbQuant
    ActiveCell.Offset(1, 0).Select
Else
End If
How do I make the alignment in the cells of columns A through E accept right-alignment by default?

I know that I can force any sort of formatting from within VBA, and indeed the formatting of column F is no big deal - I just want to find the minimum price-per-bulb.

But I am puzzled that a simple "enter this value" by VBA operates differently from a simple "enter this value" by hand.

I note in passing that column F is aligned right, and I suspect that this is related to the fact that the item to the right of the equals sign will be delivered by a calculation rather than data from a UserForm TextBox.

No million-dollar fee is dependent on this project(grin)
Thanks, Chris
You do not have the required permissions to view the files attached to this post.
There's nothing heavier than an empty water bottle

snb
4StarLounger
Posts: 578
Joined: 14 Nov 2012, 16:06

Re: Excel - alignment of numeric values in cells?

Post by snb »

Several methods:

Code: Select all

If cmdOK.Tag = "Y" Then ActiveCell.resize(,6)=array(Val(.tbPage),UCase(.tbLetter),.tbOrderNo,.tbQuant/1,--.tbCost,0+(.tbCost / .tbQuant))
NB. Ordernumber isn't a number but a string.
The 'Else' clause is redundant; in this case a oneliner suffices.
I suspect the . to tbpage e.g. is redundant if the code is in the Userform's macromodule.
A 5-digit fee will be acceptable.

User avatar
ChrisGreaves
PlutoniumLounger
Posts: 15628
Joined: 24 Jan 2010, 23:23
Location: brings.slot.perky

Re: Excel - alignment of numeric values in cells?

Post by ChrisGreaves »

snb wrote:
16 Jul 2023, 11:27
NB. Ordernumber isn't a number but a string.
The 'Else' clause is redundant; in this case a oneliner suffices.
Thanks for this speedy response, snb.
It works partially:-
Untitled2.png
The columns D and E are now aligned as they are when I enter data manually, as shown in row 20.
I thought to check my assertion about manual data (maybe I had formatted lower rows), so in row 21 I closed the UserForm and went back to entering data manually. Excepting for the item identifier within the page ("a") every string that is entered is composed of decimal digits, which I think of as "a numeric string".
The text boxes were created in the UserForm by copy/paste of the first text box, and I have not modified them in any way.

I accept your point that "Ordernumber isn't a number but a string" and that in terms of a project specification I would use "Order Identifier", in the same sense that I don't have a telephone number since "709-123-4567" is not a number but an arithmetic expression.

Too I know that the ELSE is redundant, but I have learned painfully over the years to be a devil's advocate and always ask myself "What if a condition arose when I had to deal with an alternative situation?" When checking other people's code I ask them to prove to me that the alternative condition can never apply.
Untitled3.png
I made two more essays with the UserForm In rows 22 and 23 I chose to enter into the UserForm 2-digit strings all along, wondering whether Excel2003 was deciding that a string of five decimal digits qualified as a character string. Obviously not.


I note that the Information box signals that the cell is "an error" "Number stored as text".
I suspect that somehow I have corrupted the data cells, so I will start a new workbook, copy my VBA code and experiment a bit more.

This may take a while; I have a contractor arriving to cart away two truckloads of branches.
Thanks, Chris
You do not have the required permissions to view the files attached to this post.
There's nothing heavier than an empty water bottle

User avatar
ChrisGreaves
PlutoniumLounger
Posts: 15628
Joined: 24 Jan 2010, 23:23
Location: brings.slot.perky

Re: Excel - alignment of numeric values in cells?

Post by ChrisGreaves »

ChrisGreaves wrote:
16 Jul 2023, 11:55
This may take a while; I have a contractor arriving to cart away two truckloads of branches.
... who has emailed me to say "before Wednesday, For Sure!"
I exported the two modules to disk, exited Excel, created a new workbook and saved it with the new name Vesey002.xls (attached)
I loaded two rows of data manually because I am using “Selection.End(xlDown).Select” etc and do NOT want to end up in row 65,536.\
Untitled4.png
The first row serves as column headings, so there is no way that Excel2003 can read text headings and suppose that one column is text and the other is numeric.
I populated rows three and four by using the VBA code “Sub Vesey()”, and there we go: Columns A and C are left-aligned, whereas columns B, D and E are right-aligned.
IN the VBE I select all five text boxes and choose Properties. Then I examine those properties that are empty – which to me signals that the control properties differ from each other. I see nothing that raises alarm.
I remain puzzled.
:scratch: Chris
You do not have the required permissions to view the files attached to this post.
There's nothing heavier than an empty water bottle

User avatar
DocAElstein
4StarLounger
Posts: 587
Joined: 18 Jan 2022, 15:59
Location: Re-routing rivers, in Hof, Beautiful Bavaria

Re: Excel - alignment of numeric values in cells?

Post by DocAElstein »

Hi Chris
This problem happens to me sometimes, and I have not yet figured out exactly when and why Excel does this.
But here is a way that usually gets rid of the problem:
If you select a range giving you the problems, then run this, then that will usually convert those things "number stored as text" to be like normal numbers, which may get rid of the problem. It usually does by me, and it does with your file when I try it.

Code: Select all

Sub SeeIfThisWorks()   '  https://eileenslounge.com/viewtopic.php?p=309137#p309137
 Let Selection.Value = Evaluate("=IF(ISNUMBER(" & Selection.Address & "),1*" & Selection.Address & "," & Selection.Address & ")")
End Sub
If you have any cells in the selection that are empty, then you had better use this next version instead, or else it will change empty cells into a cell with a 0 in it

Code: Select all

Sub SeeIfThisWorks2()   '   https://eileenslounge.com/viewtopic.php?p=309137#p309137
 Let Selection.Value = Evaluate("=IF(" & Selection.Address & "="""","""",IF(ISNUMBER(" & Selection.Address & "),1*" & Selection.Address & "," & Selection.Address & "))")
End Sub
Doesn't have to be the selection of course, this should do the job on your sample range

Code: Select all

Sub SeeIfThisWorks3()   '   https://eileenslounge.com/viewtopic.php?p=309137#p309137
Dim Rng As Range
 Set Rng = Worksheets.Item("Sheet1").Range("A1:F4")
 Let Rng.Value = Evaluate("=IF(" & Rng.Address & "="""","""",IF(ISNUMBER(" & Rng.Address & "),1*" & Rng.Address & "," & Rng.Address & "))")
End Sub
Or hard code it if you prefer

Code: Select all

Sub SeeIfThisWorks4()   '   https://eileenslounge.com/viewtopic.php?p=309137#p309137
Dim Rng As Range
 Set Rng = Worksheets.Item("Sheet1").Range("A1:F4")
 Let Rng.Value = Evaluate("=IF(A1:F4="""","""",IF(ISNUMBER(A1:F4),1*A1:F4,A1:F4))")
End Sub




Sub SeeIfThisWorks5()   '   https://eileenslounge.com/viewtopic.php?p=309137#p309137
 Let Range("A1:F4").Value = Evaluate("=IF(A1:F4="""","""",IF(ISNUMBER(A1:F4),1*A1:F4,A1:F4))")
End Sub
Alan
ChrisGreaves wrote:
16 Jul 2023, 14:07
ChrisGreaves wrote:
16 Jul 2023, 11:55
This may take a while; I have a contractor arriving to cart away two truckloads of branches.
... who has emailed me to say "before Wednesday, For Sure!"
Quite right to. How uncivilised of you to expect him to work on Sunday
You do not have the required permissions to view the files attached to this post.
I seriously don’t ever try to annoy. Maybe I am just the kid that missed being told about the King’s new magic suit, :(

User avatar
ChrisGreaves
PlutoniumLounger
Posts: 15628
Joined: 24 Jan 2010, 23:23
Location: brings.slot.perky

Re: Excel - alignment of numeric values in cells?

Post by ChrisGreaves »

DocAElstein wrote:
16 Jul 2023, 14:16
Hi Chris
This problem happens to me sometimes, and I have not yet figured out exactly when and why Excel does this.
But here is a way that usually gets rid of the problem:
Thanks for this, Alan
I know that I can force any sort of formatting from within VBA, and indeed the formatting of column F is no big deal - I just want to find the minimum price-per-bulb. But I am puzzled that a simple "enter this value" by VBA operates differently from a simple "enter this value" by hand.
I can engineer a solution (admittedly nowhere near as elegant as snb and yours) in VBA.

I am mainly puzzled/disturbed that I cannot track down WHY the different formatting is happening.
Cheers, Chris
There's nothing heavier than an empty water bottle

snb
4StarLounger
Posts: 578
Joined: 14 Nov 2012, 16:06

Re: Excel - alignment of numeric values in cells?

Post by snb »

@chris
I suggested 'all' code in the userform's macromodule.

@Doc
You would oblige me to once not overcomplicate simple basic VBA stuff.

The different formatting occurs, since VBA enters text that is inherent to a TextBox. Every 'number' in a textBox is a string "1234". VBA has to convert those strings into long/integer, etc.
Excel reacts differently for keyboard entry than VBA entry (e.g. copying)

VBA contains several methods to convert:

Code: Select all

c00="1234"
y=val(c00)
y=-- c00
y=0+c00
y=c00/1
y=clng(c00)
y=int(c00)
y=c00^1
Yoy can test these methods when using decimals: "1234,85" or "1234.85"
You do not have the required permissions to view the files attached to this post.

User avatar
ChrisGreaves
PlutoniumLounger
Posts: 15628
Joined: 24 Jan 2010, 23:23
Location: brings.slot.perky

Re: Excel - alignment of numeric values in cells?

Post by ChrisGreaves »

snb wrote:
16 Jul 2023, 16:14
The different formatting occurs, since VBA enters text that is inherent to a TextBox. Every 'number' in a textBox is a string "1234". VBA has to convert those string into long/integer, etc.
Excel reacts differently for keyboard entry than VBA entry (e.g. copying)
Thank you snb.
I had half of this figured out - my VBA calculation (being in VBA!) causes the cell to be loaded with a numeric result of a calculation, hence a numeric value, hence right-aligned.
The textbox contents, when loaded directly to cells, are defined to be character strings, and hence left-aligned

I think I had half of the remaining half right (DO pay attention! :grin: ) when I suggested that I "could apply formatting" in VBA.

Looking back I suspect that my second column - the letter identifier - side-tracked me. It was OK that that was treated as a character string- it was an alphabetic character after all, so left-aligned it is.
I did not know that text box contents are strings by definition.

Thank you for all of this.
Your Excel VBA is way beyond mine, so I learned something there too!

:thankyou:
Chris
There's nothing heavier than an empty water bottle

User avatar
ChrisGreaves
PlutoniumLounger
Posts: 15628
Joined: 24 Jan 2010, 23:23
Location: brings.slot.perky

Re: Excel - alignment of numeric values in cells?

Post by ChrisGreaves »

ChrisGreaves wrote:
16 Jul 2023, 16:34
I did not know that text box contents are strings by definition.
... and just to test my understanding of all this I rigged up several different ways to coerce a numeric. These solutions are not better replacements than anything posted above.
I merely wanted to go to sleep tonight with a pat on my back :grin:
Untitled6.png

Code: Select all

ActiveCell.Offset(0, 0).Value = Int(.tbPage)
ActiveCell.Offset(0, 1).Value = UCase(.tbLetter)
ActiveCell.Offset(0, 2).Value = CLng(.tbOrderNo)
ActiveCell.Offset(0, 3).Value = Val(.tbQuant)
ActiveCell.Offset(0, 4).Value = 0 + .tbCost
ActiveCell.Offset(0, 5).Value = .tbCost / .tbQuant
ActiveCell.Offset(1, 0).Select
That's just the sort of exercise I would have suggested in class, to drive the point home.
Cheers, Chris
You do not have the required permissions to view the files attached to this post.
There's nothing heavier than an empty water bottle

snb
4StarLounger
Posts: 578
Joined: 14 Nov 2012, 16:06

Re: Excel - alignment of numeric values in cells?

Post by snb »

But please, do not use 'select' in VBA.

User avatar
DocAElstein
4StarLounger
Posts: 587
Joined: 18 Jan 2022, 15:59
Location: Re-routing rivers, in Hof, Beautiful Bavaria

Re: Excel - alignment of numeric values in cells?

Post by DocAElstein »

Hello,
I was checking through some stuff related to things in this Thread: I started doing an extended explanation of Evaluate Range one liner type solutions, using my solution here as just one example.
But then after a while I realised that my solution was a bit messed up: It worked by lucky chance and not for the reason I thought.
So I went off on quite a few tangents, re discovering a lot more about range objects, Evaluate(" ") , putting things in cells and in particular what this typical pseudo code line is all about
Range2.Value = Range1.Value
I came to the conclusion that most of us have got it totally wrong. (I am not saying I am right, Lol, that is just the conclusion I came to, :-) )
Anyway, as a spin off I think I can do a couple of useful contribituons here.
_(i) Give a better solution
_(ii) Give a layman geuss to answer partially, the main question
ChrisGreaves wrote:
16 Jul 2023, 16:10
... track down WHY the different formatting is happening...
_.___________

_ (i) My solution here is a mess.
These two are better, ( working on one of the test data ranges, A1:F7 used in a file uploaded by Chris)

Code: Select all

 Sub Betta() '   https://eileenslounge.com/viewtopic.php?p=309151#p309151
Rem 0 test data range
Dim Ws1 As Worksheet
 Set Ws1 = ThisWorkbook.Worksheets("Sheet1")
Dim Rng As Range
 Set Rng = Worksheets.Item("Sheet1").Range("A1:F7")
 Rng.Offset(0, Rng.Columns.Count + 1).Clear
Rem 1 Evaluate Range one liner type solution
 Let Rng.Offset(0, Rng.Columns.Count + 1) = Evaluate("IF(A1:F7="""","""",A1:F7)")

 Rng.Offset(0, Rng.Columns.Count + 1).Clear
Rem 2 Another solution
 Let Rng.Offset(0, Rng.Columns.Count + 1) = Evaluate("A1:F7").Value(RangeValueDataType:=xlRangeValueDefault) 'For Excel 2007 +
 Let Rng.Offset(0, Rng.Columns.Count + 1) = Evaluate("A1:F7").Value 'For Excel 2003 and lower
End Sub
I got this far after about 30 long posts, too long and detailed to repeat.
For completeness and further reference I will give a few links, but I am not sure I would recommend taking a look unless you have a lot of time and interest.
Excel Functions ISTEXT and ISNUMBER
Explanations for my original Evaluate Range one liner until I realised I messed up
Starting again with hindsight. The new solution
Range Object Default Properties (Methods?)
Code line type Range2.Value = Range1.Value Question from the web
New Solution(s)


_._______________________________________

_(ii) An answer Idea to the main question of the Thread.
….. next post…..
Last edited by DocAElstein on 14 Aug 2023, 18:56, edited 1 time in total.
I seriously don’t ever try to annoy. Maybe I am just the kid that missed being told about the King’s new magic suit, :(

User avatar
DocAElstein
4StarLounger
Posts: 587
Joined: 18 Jan 2022, 15:59
Location: Re-routing rivers, in Hof, Beautiful Bavaria

Re: Excel - alignment of numeric values in cells?

Post by DocAElstein »

_(ii) An answer Idea to the main question of the Thread.

It’s a bit of a gut Layman feeling based on a lot of stuff in those links. Just an idea.
I am not considering copying and pasting. Just because I am not and wasn’t. What I have spent some time looking at on and off for a week or two, is range objects, Evaluate(" ") , putting things in cells, and in particular what this typical pseudo code line is all about
Let Range2.Value = Range1.Value
The LHS of that pseudo code line “writes stuff in a cell”, and most often using that will not get the Number stored as text thing, even if you use it to put in a string or string variable, or even an element from a sting type array. Excel will mostly do what it does when you manually type stuff in and it will decide what type it is and how to show it. If it looks like a number, that is what you will get - a number, in the cell even if it was a string that got put in. The main exception to that I found is if you try to put in an array of string type elements, and it must be the array you put in, even if it is just one cell. If you put in a single element you won’t get that Number stored as text thing.

So, What is going on
This is an idea, a wild theory:
Low level computer stuff does not understand what a single value is. That is a human concept it don’t understand. Excel is a high level thing to interface with us humans and a lot of effort is put into making things appear in a box in different formats. Similarly, VBA , unlike more low level , more efficient computer stuff, is quite tolerant when you put a text that looks like a number in something wanting a number.
I am thinking that a computer lower down thinks in arrays all the time, so it works more efficiently with lots of data at once, not one value at a time. I am thinking that string type arrays are maybe most of what computers are.
We can use other things either external to Excel or things that were developed from more fundamental low level stuff. That could be the case with Text box. Perhaps when it puts stuff in a cell it uses more low level stuff. You might think you are putting a value in a cell from it. But I am suggesting you are putting an array in, but perhaps just restricting what you see of it by virtue of what you do on the LHS of that code line.

I think a lot of low level stuff in computers is about String manipulation. I often heard smarter people tell me string functions are old, fundamental, and therefore efficient. Chris told me once computers are just strings. I wonder perhaps if we could advance that a bit and say computers are just arrays of strings, or string arrays, possibly one dimensional**, interacting. (** What we think are two dimensional arrays are just 1 dimensional arrays of 1 dimensional array elements, or it’s all just a lot of complex offsets, which is the same thing just said a bit differently, perhaps)

This simple macro will demo some of my thinking

Code: Select all

 Sub ComputerStuff() ' https://eileenslounge.com/viewtopic.php?p=309144#p309144
Dim Ws As Worksheet: Set Ws = ActiveSheet
Dim Computer1() As String, Computer2(1 To 1) As String, Excl(1 To 1) As Variant, Str As String
 Let Computer1() = Split("1 2"): Let Computer2(1) = "3": Let Excl(1) = "4": Let Str = "5"
 
' These next lines all get you that   Number stored as text   thing        This is doing something at a low level that you as a human can't do, and Excel probably does not try to do so much with it and it gets put in quite quickly and efficiently
 Let Ws.Range("A20") = Computer1()
 Let Ws.Range("A21:B21") = Computer1()
 Let Ws.Range("A22") = Computer2()
 
' These don't get you that    Number stored as text    thing               This is putting a value in a cell in a similar way to what you as a human can, and Excel probably takes a look at it and has a go at doing something with it before it finally gets put in
 Let Ws.Range("A23") = "6"
 Let Ws.Range("A24") = Str
 Let Ws.Range("A25") = Computer1(0)
 Let Ws.Range("A26") = Computer2(1)
 Let Ws.Range("A27") = Excl(1)
 Let Ws.Range("A28") = Excl()
End Sub 
Computer String Stuff.JPG
Perhaps the reason why the makers of Excel decided to give you that warning is that if you are in a habit of using things that put things in a cell using more low level stuff, then maybe you will also take that data and put into other more low level stuff, or use it in more low level programming, in which case you might get the type mismatch problems that you experience more often in more low level coding.


That’s it, just a layman idea, I thought I would post it and run, :flee:

:-)
Alan


_.__________________________________________________________________

Number stored as text, alignment of numeric values in cells.xls https://app.box.com/s/ruodtsrly19ru3dv2d1404bykvhjrdsw
VBA Evaluate Range Value values Aug 2023.xls https://app.box.com/s/puxvbuyjz1s4fyu9r3bsjtdtr8qijph6
You do not have the required permissions to view the files attached to this post.
I seriously don’t ever try to annoy. Maybe I am just the kid that missed being told about the King’s new magic suit, :(

User avatar
SpeakEasy
4StarLounger
Posts: 550
Joined: 27 Jun 2021, 10:46

Re: Excel - alignment of numeric values in cells?

Post by SpeakEasy »

>I often heard smarter people tell me string functions are old, fundamental, and therefore efficient

They clearly knew nothing about VBA strings, then

User avatar
ChrisGreaves
PlutoniumLounger
Posts: 15628
Joined: 24 Jan 2010, 23:23
Location: brings.slot.perky

Re: Excel - alignment of numeric values in cells?

Post by ChrisGreaves »

SpeakEasy wrote:
14 Aug 2023, 20:45
>I often heard smarter people tell me string functions are old, fundamental, and therefore efficient
They clearly knew nothing about VBA strings, then
To anyone with an interest in computers as strings, besides my PROJE application (which generates an Instr-searchable single-string of every scrap of VBA code on a hard drive partition) there is an excellent book "The Annotated Turing" by Charles Petzold
20230814_190901.jpg
20230814_190831.jpg
On page 141 Petzold points out that WinWord.exe is a machine that can be described as a single number, albeit a number of 29 million decimal digits.
That large number can be considered as a single string of decimal digits.

We should note that Alan Turing's work specified a Turing Machine as a table of commands, each command translatable to a symbol.

My Turing Machine interpreter is itself written in Word2003 VBA.
Cheers, Chris
You do not have the required permissions to view the files attached to this post.
There's nothing heavier than an empty water bottle

User avatar
DocAElstein
4StarLounger
Posts: 587
Joined: 18 Jan 2022, 15:59
Location: Re-routing rivers, in Hof, Beautiful Bavaria

Re: Excel - alignment of numeric values in cells?

Post by DocAElstein »

I thought VBA string functions were based on older VB string functions. I often found good info about the string functions in older VB literature.
I seriously don’t ever try to annoy. Maybe I am just the kid that missed being told about the King’s new magic suit, :(

snb
4StarLounger
Posts: 578
Joined: 14 Nov 2012, 16:06

Re: Excel - alignment of numeric values in cells?

Post by snb »

An Array can contain any kind of value.
You can easily convert that array into an exclusive array of strings:

Code: Select all

Private Sub cmdOK_Click()
    Sheet1.Cells(Rows.Count, 1).End(xlUp).Offset(1).Resize(, 6) = Array(tbPage, tbLetter, CLng(tbOrderNo), Val(tbQuant), --tbCost, 0 + (tbCost / tbQuant))
    Sheet1.Cells(Rows.Count, 1).End(xlUp).Offset(1).Resize(, 6) = Split(Join(Array(tbPage, tbLetter, CLng(tbOrderNo), Val(tbQuant), --tbCost, 0 + (tbCost / tbQuant))))
    Hide
End Sub

User avatar
SpeakEasy
4StarLounger
Posts: 550
Joined: 27 Jun 2021, 10:46

Re: Excel - alignment of numeric values in cells?

Post by SpeakEasy »

DocAElstein wrote:
15 Aug 2023, 07:13
I thought VBA string functions were based on older VB string functions. I often found good info about the string functions in older VB literature.
Doesn't make them efficient, though.

snb
4StarLounger
Posts: 578
Joined: 14 Nov 2012, 16:06

Re: Excel - alignment of numeric values in cells?

Post by snb »

@Doc

I think it's only when you enter a value in just 1 cell in Excel, that Excel interprets what kind of value you have entered (string, number, date). Although it might be practical in the UI, it is annoying that the result in VBA is different from what you intend. What your 'Landsleute eine Verschlimmbesserung nennen'. Excel shouldn't interfere with VBA.

User avatar
DocAElstein
4StarLounger
Posts: 587
Joined: 18 Jan 2022, 15:59
Location: Re-routing rivers, in Hof, Beautiful Bavaria

Re: Excel - alignment of numeric values in cells?

Post by DocAElstein »

I think it's only when you enter a value in just 1 cell in Excel, that Excel interprets what kind of value you have entered (string, number, date). .....
That doesn't apopear to be what I am seeing....Excel seems to interfere with values put in cells from a Variant type array.
In this example Excel changes the strings to numbers for the case of the Variant type array.
(It does not interfere with the same from a String type array, which was part of my discussions).

Code: Select all

Sub PutItInCells() ' http://www.eileenslounge.com/viewtopic.php?p=310051#p310051
Rem 0
Dim Ws As Worksheet
 Set Ws = ThisWorkbook.Worksheets("Sheet1")
Dim Var(1 To 2) As Variant, Str(1 To 2) As String
 Let Var(1) = "10": Var(2) = "11": Str(1) = "10": Str(2) = "11"
Ws.Range("A15:B16").Clear
 
Rem 1
 Let Range("A15:B15") = Var()
 Let Range("A16:B16") = Str()

Debug.Print Range("A15:B16").Value(RangeValueDataType:=xlRangeValueXMLSpreadsheet)   '           Excel 2007+ only!!!                                                 https://learn.microsoft.com/en-us/office/vba/api/excel.xlrangevaluedatatype   xlRangeValueDefault 10    xlRangeValueMSPersistXML    12      xlRangeValueXMLSpreadsheet  11                           https://fastexcel.wordpress.com/2017/03/13/excel-range-valuevaluetype-what-is-this-parameter/
End Sub

Excel interferes with Elementts put in from Variant type array.JPG


It’s this phenomena, which leads to the simple solution to get rid of those displayed warnings with a simple code line, pseudo like
Let RangeX = RangeX.Value(RangeValueDataType:= xlRangeValueDefault)
, since the RHS returns a Variant Type array of values, and the LHS puts that array back in the RangeX, and then Excel does its interference/conversion. ( It has the advantage over my Range Evaluate solution of also preserving Emptys since the Evaluate(" ") seems to change those to 0. I am not sure why the Evaluate(" ") does that, possibly some sort of wired in mathematical default thing )



(Part of my abstract thinking was that Variants are high level complex stuff that Excel is all about in the user interface to us, so looks at them things, whereas string arrays are possibly more low level fundamental stuff, and for some reason bypasses some of the interface wiring when put in a cell or cells. ( A single string value will get interpreted / interfered by Excel, so would a single element from a String Type array. But not a string array, even if it is only a one element array) )
You do not have the required permissions to view the files attached to this post.
I seriously don’t ever try to annoy. Maybe I am just the kid that missed being told about the King’s new magic suit, :(