I tried to make a macro udf to answer someones strange question on StackOv.
Maybe I took it the wrong way and he was just asking as a freshman or 'just asking', but I treated it seriously. Thought he was a sudent fro his project or a busiess man. Anyway. It really got me going, The question was amazing wonderful it seemed to me.
"Q:
Is there any way to add ellipsis(three dots) at the end of a data in excel if it exceeds the limit of the cell? [closed]"
"Can we put lengthier data in limited space in excel as it disturbs view of the data in empty cells by going over it?
We have an alternative to wrap the text but that increases width of the cell. Rest if the cell width is too small we could see ########.
What i want is:
Abc, Batman, Spiderman | America, India, Australia |
To be shown as:
Abc, Bat... | America, Ind... | "
That was his qustion.
@juDV made an interesting point: "Using a formula would mean altering the actual value losing what you had when you started of. You sure that's what you want? – JvdV Jul 21 at 21:02 "
heress my resonses:
so I set about doing it - why not - I had free time and was in my favourtite place at the moment (St Pauls area london).
This is what I came up with :
Which works. Does a job - atleast proved point it can be done.
But to answer address the experts concerns & my own suspictions & doubts (re: cell loosing its value), I tried to (and succeeded , at least in the meaning of discovering ways to parse own formula and arguments, Application.Caller.Formula & Application.ThisCell.Formula , which I became very excited about) make a better formula. Got it - forced it - to work:
Public MyString1e As Variant
Public MyString1u As String
Public arg22 As Variant
but it doesnt. Its a sister function at best. Because:
=valueshown5("A"&eval(AU29),1)
WORKS!! & im happy about (I put the eval in to test. Its not part of the oppration of the fuction. It was just to test its scope/dynamism.
ftr in my tests, AU29 = =SUBSTITUTE(SUBSTITUTE(FORMULATEXT(BA19),"=JustAppear256(",""),",1)","") where justappear256 was just the same or similar or ValueShown5 or JustAppear33AG (which I reckoned upto last night when I got JustAppear33AG to work was the best, as it was alllowing the ability to store the 1st Argument/parameter somewhere and only work on its copy only. ok)
But, =JustAppear33AG(eval2(AU29),1) returns error. It must be to do with the way I am parsing/handling the parameters of JustAppear33AG (what I hoped was my better and more "functional for the future" fucntions, with posibilities to store the parameter/argument values so that other functions would refer to these (and not the appearance of the cell) code ) .
Im wondering if anyone can help me develop my code , and or make it work for when i out evals/or evaluatestrings in the parameter for the 2nd udf.
SO have closed the question yesterday (not asked by mysefl) but they let me work on it everyday since then. I just hope I don't get a typical SO answer here and actually get someone who can engage with me , and help make better the proof of concept and / or code.
Maybe I took it the wrong way and he was just asking as a freshman or 'just asking', but I treated it seriously. Thought he was a sudent fro his project or a busiess man. Anyway. It really got me going, The question was amazing wonderful it seemed to me.
"Q:
Is there any way to add ellipsis(three dots) at the end of a data in excel if it exceeds the limit of the cell? [closed]"
"Can we put lengthier data in limited space in excel as it disturbs view of the data in empty cells by going over it?
We have an alternative to wrap the text but that increases width of the cell. Rest if the cell width is too small we could see ########.
What i want is:
Abc, Batman, Spiderman | America, India, Australia |
To be shown as:
Abc, Bat... | America, Ind... | "
That was his qustion.
@juDV made an interesting point: "Using a formula would mean altering the actual value losing what you had when you started of. You sure that's what you want? – JvdV Jul 21 at 21:02 "
heress my resonses:
- Good question, Not that I want to change your question, but perhaps doing something else like changing highlight,/fill cell colour? font colour? or adding a comment mark to such cells? would any of those be other equivalent ways of solving your need or problem and satisfying all the benefits you imagine the ... would bring? – Spyros Tzortzis Jul 21 at 21:43
Not neccissarily @Judv im thinking. Because couldn't say a udf be written to store the actual value of the original formula resulyt in memory (which it is anyway)/an array, so the truncated portions of the original result, could be replaced per cell if doing a =myreplace(cell,"...",original data result of the cell) , or realresultUDF(cell). or something like udfGoBack/FlipBack?. ... No, hang on UDF would be like =Shownvalue(the original formulas,1 or 0) with 1 or 0 denoting the flip switch between real actual result and the ... version. I think it could be done/made. – Spyros Tzortzis Jul 21 at 21:55
so I set about doing it - why not - I had free time and was in my favourtite place at the moment (St Pauls area london).
This is what I came up with :
Code:
Function valueshown5(cell6 As Variant, toggleswitch As Boolean) As Variant
If toggleswitch = False Then
valueshown5 = cell6
Else
If Len(cell6) > Application.Caller.ColumnWidth Then
valueshown5 = Replace(cell6, Right(cell6, Len(cell6) - Application.Caller.ColumnWidth - 3), "...")
Else: valueshown5 = cell6 & " - ok" ' it seems daft as this could go over too, but Its just to test it.
End If
End If
End Function
Which works. Does a job - atleast proved point it can be done.
But to answer address the experts concerns & my own suspictions & doubts (re: cell loosing its value), I tried to (and succeeded , at least in the meaning of discovering ways to parse own formula and arguments, Application.Caller.Formula & Application.ThisCell.Formula , which I became very excited about) make a better formula. Got it - forced it - to work:
Public MyString1e As Variant
Public MyString1u As String
Public arg22 As Variant
Code:
Function JustAppear33AG(cell6 As Variant, toggleswitch As Boolean) As Variant 'changed cell6 from variant to string ||| wth arg2 only 25/7/2020 JustAppear33AG - next one will have arg2 evaluated [arg2]=arg2 18:47 25/07/2020
'Dim MyString As String
MyString1e = [cell6]
MyString1u = cell6
Dim cell67 As Range
Dim formulacell6arg As Variant 'its as string??? idk
formulacell6arg = Application.Caller.formula 'Value2
'thiscell2 = ThisCell.formula
'foo = Evaluate("Formulatext(" & ThisCell & ")")
'zz = GetFormula(cell6)
'zz = GetFormula(ThisCell)
'ccc = chr(34) & ThisCell & chr(34)
'ccc4 = Range(ccc).Formula2
Dim arg3 As Variant
'cell7 = Trim(cell6)
'I = InStr(func, "(") 'nope dont need this. dont care whats in it. I just want it all as written by user
arg1 = Mid(cell6, 1, Len(cell6)) 'did not work the way id expected it to (it just mid's the evaluation of cell6)
'arg1 = Mid(args, 1, Len(args) - 1) swear I dont need this
'' This worked ;; arg1 = Evaluate("Text(" & cell6 & ")")
'' arg2 = Evaluate("FormulaText(" & ActiveCell.Address & ")")
'' arg2 = formulacell6arg '=MID(AO26,LEN("JustAppear33AG(")+1,LEN(AO26)-LEN("JustAppear33AG(")-3)
arg22 = Mid(formulacell6arg, Len("JustAppear33AG(") + 2, Len(formulacell6arg) - Len("JustAppear33AG(") - 4) 'first arg/par wss +1 - now its +2;44 25/07/2020)
arg3 = Evaluate([arg22]) 'Worksheets.Evaluate(Trim(arg22)) '==="=" /// '''' Eval(arg2) '
'If Len(MyString1e) > 1 Then
If toggleswitch = False Then
JustAppear33AG = Evaluate([arg22]) 'wow look what I have discovered ! 21:45 25/07/2020 :) W. LL HH LL Hh LL
Else
If (Len(cell6)) = Application.Caller.ColumnWidth Then
JustAppear33AG = Evaluate([arg22])
Else
If Len(cell6) - 3 > (Application.Caller.ColumnWidth * 1.6666) Then '25/07/020 21:48 - had it arg3 just a minute ago. trying to improve the column reactions
JustAppear33AG = Replace(arg3, Right(arg3, Len(arg3) - Application.Caller.ColumnWidth - 3), "...")
'Len(cell6) & " - " & Application.Caller.ColumnWidth '
Else: JustAppear33AG = arg3 & " - ok" ' it seems daft as this could go over too, but Its just to test it.
'Len(cell6) & " - " & Application.Caller.ColumnWidth
'ActiveCell &
End If
End If
End If
' Else: JustAppear33AG = ThisCell.Address & arg3 & "Error" ' this just doesnt let single digit characters to be evaluated/ I was trying something else but that didt work,so just chnged the parameters to 1-digit
'End If
End Function
'cound trey & chnge arg3's to cell6 or
but it doesnt. Its a sister function at best. Because:
=valueshown5("A"&eval(AU29),1)
WORKS!! & im happy about (I put the eval in to test. Its not part of the oppration of the fuction. It was just to test its scope/dynamism.
ftr in my tests, AU29 = =SUBSTITUTE(SUBSTITUTE(FORMULATEXT(BA19),"=JustAppear256(",""),",1)","") where justappear256 was just the same or similar or ValueShown5 or JustAppear33AG (which I reckoned upto last night when I got JustAppear33AG to work was the best, as it was alllowing the ability to store the 1st Argument/parameter somewhere and only work on its copy only. ok)
But, =JustAppear33AG(eval2(AU29),1) returns error. It must be to do with the way I am parsing/handling the parameters of JustAppear33AG (what I hoped was my better and more "functional for the future" fucntions, with posibilities to store the parameter/argument values so that other functions would refer to these (and not the appearance of the cell) code ) .
Im wondering if anyone can help me develop my code , and or make it work for when i out evals/or evaluatestrings in the parameter for the 2nd udf.
SO have closed the question yesterday (not asked by mysefl) but they let me work on it everyday since then. I just hope I don't get a typical SO answer here and actually get someone who can engage with me , and help make better the proof of concept and / or code.