This post https://www.excelfox.com/forum/showt...age2#post21998 Post #15
Some notes on support of these Threads and posts
https://eileenslounge.com/viewtopic....309151#p309151
https://www.excelfox.com/forum/showt...ll=1#post22078
Why did we Stop after the last few posts
We need to start again with the Evaluate(" "), that is to say the RHS _____ = Evaluate(" ") thing , and consider at the same time the RHS range thing _____ = Range(" ")
_ RHS _____ = Evaluate(" "), and RHS range object assignment thing _____ = Range(" ")
There seems to be some similarity in things they do
What is Evaluate(" "), with emphasis with what goes on in a spreadsheet cell
(Or what is going on in a cell after typing = ). I think maybe that when in a [cell] you write = , it can be considered as similar to this pseudo coding in VBA
[write in Cell] = Evaluate("What you put in the cell after the = ")
In simple terms, to a first approximation, Evaluate(" ") allows you to do in VBA within the " " what you do after the = in a cell.
([color=grey]So perhaps its understandable that
_ you can omit the = within the " " in Evaluate(" "), although it is accepted syntaxly: Perhaps it is then just redundant* since Evaluate is about doing what is after the = in an Excel cell
_ You can’t just put simple text in evaluate, as you can with a cell, you need to do it as
___ ' 1a)(i) you can additionally give text in a cell, as part of a formula, ( Example In cell ="Text in Formula in Excel"
___ ' 1a)(ii) or carefully tell the Evaluate(" ") to take/Evaluate a literal string, rather than Evaluate the string as if it were something after a = in a cell, which is what Evaluate is about*
Range objects in spreadsheets and Excel worksheet functions returning a range object. )
When we use cells in a spreadsheet, we may appear to be using simple text, numbers and formulas. Often we may have a formula which finally gives us a number. In some cases we may indeed get a simple number result. Within a formula, cell references may appear to just get the number or text from a cell, but in fact Excel manipulates range objects. Once you have some basic VBA knowledge, this will perhaps make sense, especially if you are aware that it is something similar to VBA that makes what you see work: Think of Excel spreadsheets as lots of functions that trigger when you change things in cells.
Bearing this in mind, it is perhaps reasonable to expect that things like Evaluate("=A1") , Evaluate("A1:B2") etc. in VBA might return a range object. Indeed they do!
You must make sure to do a Set them to a range object on the LHS,
Set Rng = Evaluate("=A1")
If you Let them to a Variant variable, (or for the case of a single cell, any suiting variable type), then VBA seems to be written to oblige and give an array of values (or a value for a single cell)
Code:
Sub RangeEvaluate() ' https://www.excelfox.com/forum/showthread.php/2909-Appendix-Thread-Evaluate-Range-(-Codes-for-other-Threads-HTML-Tables-etc-)?p=22078&viewfull=1#post22078
Rem 0
Dim Ws As Worksheet
Set Ws = ThisWorkbook.Worksheets("RangeValuevalues")
Ws.Range("B1").Clear
Rem 1 write in Cell, a value and something else - I want to do this cell writing from VBA ="Text in Formula in Excel"
' 1a)(i)Excel value is = " Text in Formula in Excel " in other words a formula
Let Ws.Range("B1") = "=" & """" & "Text in Formula in Excel" & """" ' This is like manually writing ="Text in Formula in Excel" in a cell, a formula or like saying is to be evaluated "Text in Formula in Excel"
Ws.Range("B1") = "=""Text in Formula in Excel""" ' simplid Alternative - take out all " & " since in VBA they stop text" and lin& to "start of another text
Ws.Range("B1").Clear ' is " = " " Text in Formula in Excel " " "
Let Ws.Range("B1") = Evaluate("=" & """" & "=" & """" & """" & "Text in Formula in Excel" & """" & """" & """"): Debug.Print "=" & """" & "=" & """" & """" & "Text in Formula in Excel" & """" & """" & """" ' It is always worth doing this to see what text Evaliate(" ") actually sees inside the " " , in this case it gives in Immediate Window ="=""Text in Formula in Excel"""
Ws.Range("B1") = Evaluate("=""=""""Text in Formula in Excel""""""") ' Alternative https://i.postimg.cc/W3n3Q2ST/Remove-some-in-VBA-Quote-Ambersand-Quote.jpg
' 1a)(ii) use Evaluate to put simple text in a cell, sort of, it actually does an evaluation of the literal string, perhaps a combination of the = and then the final carriage return
Ws.Range("B1").Clear: Debug.Print "=""Text in Formula in Excel""" ' It is always worth doing this to see what text Evaliate(" ") actually sees inside the " " It gives in this case ="Text in Formula in Excel" But this is not quite the equivalent of what you would write in a cell, since Excel would not try to evaluate and error instead https://i.postimg.cc/htQPr8dL/Wtire-Text-in-Formula-in-Excel-in-a-Cell-and-it-will-error.jpg
Ws.Range("B1").Clear: Let Ws.Range("B1") = Evaluate("=""Text in Formula in Excel"""): Debug.Print "=""Text in Formula in Excel""" ' gives ="Text in Formula in Excel" or try ? "=""Text in Formula in Excel""" ="Text in Formula in Excel" This is extra to Evaluate(" ") - it is attempting to evaluate a string of Text in Formula in Excel, like =Text in Formula in Excel and it recognises that as a text, so puts that in the cell Watch : : Evaluate("=""Text in Formula in Excel""") : "Text in Formula in Excel" : Variant/String : Tabelle6.RangeEvaluate
'1b) Something Else
In the first cell, A1, we have a number held as text. The range object seems to know this, and we find that if we try to write that in another cell, ( Let LHS = ) then we don’t get an error, but rather the text is put in. This is a strange thing, and its discussed in more detail somewhere else, ( Post is #21995 Page2 #12 https://www.excelfox.com/forum/showt...age2#Post21995 ) , but important for our considerations here is that it is a range object phenomena, so in '1b) we compare what happens for the RHS of Range(" ") or Evaluate(" ").
The result is the same.
In fact, not known to many people, some Excel functions also return range objects, ( https://eileenslounge.com/viewtopic....280942#p280942
https://www.myonlinetraininghub.com/...#comment-84892 February 20, 2021 at 3:18 am ). and we find that the behaviour in what happens for the RHS of Range(" ") or Evaluate(" ") is consistent for this as well, it’s the same again
Code:
'1b) Something Else https://www.youtube.com/watch?v=Td3r55oyiu0
Ws.Range("A2").Clear
Let Ws.Range("A2") = Ws.Range("=IF(1,A1)") ' Watch : + : Ws.Range("=IF(1,A1)") : "44" : Object/Range : Tabelle6.RangeEvaluate
Ws.Range("A2").Clear
Let Ws.Range("A2") = Ws.Evaluate("=IF(1,A1)") ' Watch : + : Ws.Evaluate("=IF(1,A1)") : "44" : Variant/Object/Range : Tabelle6.RangeEvaluate
So far so good.
What’s all this got to do with my Evaluate range one liner answer here: https://eileenslounge.com/viewtopic....309137#p309137
Well, I was trying to get a number held as text to change to a number, (to get rid of the little warning and the alignment difference to that for a number). My solution was based on pseudo code of CellValue x 1, as this is a typical way in Excel, or computing generally, to get a text that looks like a number to become a true number.
It worked.
But then when I looked at this in more detail, I thought it shouldn’t
https://www.excelfox.com/forum/showt...el-Cell/page10
https://www.excelfox.com/forum/showt...el-Cell/page11
, and then I went right back to re learn about range objects in particular with reference to the typical code line of
Range2.Value = Range1.Value
https://www.excelfox.com/forum/showt...el-Cell/page12
I know enough now to start again.
https://www.excelfox.com/forum/showt...ll=1#post23185
https://www.excelfox.com/forum/showt...ll=1#post23186
https://www.excelfox.com/forum/showt...ll=1#post23189
Bookmarks