I have string "02Years02Months". In the SSRS Report i need to show the string like
"02 Years 02 Months". Is there any good method in SSRS report Expression.
Please advice, Thanks
=Left(Fields!String.Value, 2) & " " & Mid(Fields!String.Value, 3, 7) & " " & Right(Fields!String.Value, 6)
That's assuming your numbers will always be padding with zeroes as in the example above, and given you replace the Fields!String.Value with the field containing the string being returned in your report.
I found the solution, Here is the answer
=Left(Fields!Value, 2) & " " & Mid(Fields!Value, 3, 5) & " " & Mid(Fields!Value, 8, 2) & " " & Right(Fields!Value, 6)
Thanks for the support
Related
Im currently figuring out how to write "&" in a formula so that VBA recognizes it as a string and not as the &-operator.
My formula looks like this:
"=AVERAGEIF(RC[-4]:R[" & Total & "]C[-4],"">""&0.5*MAX(RC[-4]:R[" & Total & "]C[-4]))"
But it should look something like this, as I want to use the variable z instead of 0.5
"=AVERAGEIF(RC[-4]:R[" & Total & "]C[-4],"">"" & Chr(34)& Chr(38) & Chr(34)& z & *MAX(RC[-4]:R[" & Total & "]C[-4]))"
As you see I already tried to write the "" and the & as ASCII but it seems that even this doenst work.
Thanks in advance for your help!
EDIT: The result should look like this:
=AVERAGEIF(C31:C6413;">"&0.5*MAX(C31:C6413))
EDIT: will post another question with the whole code. See here
I wouldn't use Chr(34) for " and Chr(38) for &, they're unnecessary indirection making the code harder to reason about. & doesn't need escaping, and to have a " literal inside a string you escape it by doubling it up, so """" is a string containing a single " character.
Concatenating long strings with escaped double-quotes can be a frustrating experience... what if we broke down the steps, and added a bit of space around operators?
The cognitive load is immediately reduced, and any error in the logic is much easier to spot:
Dim avgSourceRangePart As String
avgSourceRangePart = "RC[-4]:R[" & Total & "]C[-4]"
Dim maxPart As String
maxPart = "MAX(RC[-4]:R[" & Total & "]C[-4])"
Dim avgConditionPart As String
avgConditionPart = """>"" & " & z & " * " & maxPart & ")"
Now the final concatenation looks like this:
"=AVERAGEIF(" & avgSourceRangePart & "; " & avgConditionPart ")"
This should be what you're looking for:
"=AVERAGEIF(RC[-4]:R[" & Total & "]C[-4],"">"" &" & z & "*MAX(RC[-4]:R[" & Total & "]C[-4]))"
I have a syntax error in this VBA code:
students.Cells(studentRow, StartColumn).Formula = _
"=If($" & SurnameColumnStr & studentRow & " <> """", if($" & colonnaStr & studentRow & _
" <> """", $" & colonnaStr & " & $" & pointRow & ", 0), """")"
I can't put right this piece of code: $" & colonnaStr & " & $" & pointRow & " (it would be like having "$B$3")
I've tried several ways with no luck.
Any help would be really appreciated.
To get "$B$3" out of colonnaStr (a column reference) and pointRow (a row reference), you will need to use Range.Address.
Using this inside your Formula String:
Range(colonnaStr & pointRow).Address(True, True, xlA1)
Will give you $B$3 as a result.
To learn more about is, read HERE
I have the following formula that I want to insert into a cell but it has multiple double quotes and I can't seem to make it work. There is plenty of solutions on the web but most have 1 or 2 sets of double quotes. I tried double quotes on all double quotes but it gives me a runtime error 438 object doesn't support this property
Here is the formula that I want to insert:
="Closing Costs" & " Current Buffer" & " " &TEXT('Closing Costs'!D32,"$ 0")
Here is the code that is not working:
ActiveSheet.Range("F18").Value = "=""Closing Costs"" & ""
Current Buffer"" & "" "" &TEXT('Closing Costs'!D32,""$ 0"")"
The following should work (all on one line):
ActiveSheet.Range("F18").Value = "=""Closing Costs"" & "" Current Buffer"" & "" "" &TEXT('Closing Costs'!D32,""$ 0"")"
It looks the same as your sample - but perhaps looks here are deceptive.
Using the chr() command can be helpful in these scenarios. chr(34) returns a double quote character, so the below should do the trick.
ActiveSheet.Range("F18").Value = "=" & chr(34) & "Closing Costs Current Buffer" & chr(34) & " " & chr(34) & TEXT('Closing Costs'!D32," & chr(34) & "$ 0" & chr(34) & ")"
It’s a little bit longer, but I find using chr(34) to be a little easy to determine quotation placement.
I have a table in Excel that has 10 columns. For each row there are different numbers of cells populated e.g.
My concatenated string is as follows for HTML emails
(" + Machine1 + ", " + Machine2 + ", " + Machine3 + ", " + Machine4 + ", " + Machine5 + ", " + Machine6 + ")
However I want the comma to not show after the last cell in the row (whether that be column 3,4,5,6).
This is what I get
(TEST1, TEST2, TEST3 , TEST4, TEST5, , )
I want to remove the two commas at the end. Hope this makes sense!
If you have Office 365 Excel then use TEXTJOIN:
="(" & TEXTJOIN(", ",TRUE,A2:F2) & ")"
If not then you will need to use IF for each return and Mid:
=MID("(" & IF(A2 <> "",", " & A2,"") & IF(A2 <> "",", " & B2,"") & IF(C2 <> "",", " & C2,"") & IF(D2 <> "",", " & D2,"") & IF(E2 <> "",", " & E2,"") & IF(F2 <> "",", " & F2,""),3,999)
Alternative without IF
Just in addition to Scott's valid solution, I demonstrate an approach via the REPT function. Applied on a cell containing a string, it "repeats" its content & comma once (indicated by COUNTA() equalling 1), whereas an empty cell results in a zero repetition which allows to omit not only the cell content but the comma, too:
="(" & SUBSTITUTE(REPT(A1&",",COUNTA(A1))&REPT(B1&",",COUNTA(B1))&REPT(C1&",",COUNTA(C1))&REPT(D1&",",COUNTA(D1))&REPT(E1&",",COUNTA(E1))&REPT(F1&",",COUNTA(F1))&"$",",$",")")
A simple SUBSTITUTE removes the last comma, wherever it occurs before the closing bracket ")".
I've searched extensively for the answer to my question and I'm at an impasse.
I'm trying to pass a formula to excel with applescript. The problem is the quotes around the spaces that I want to place between fields. I've used "\" to escape the quotes but it throws an error. To make it more complicated the row number is a variable "i". Here is the formula in excel format:
=CONCATENATE(A2," ",B2," ",C2," ",D2)
Here is the formula in applescript-ese (works but does not produce spaces in data):
set rowCount to (((count of rows of used range of active sheet)) + 1)
repeat with i from rowCount to 2 by -1
set formula of row i of column 15 to "=CONCATENATE(A" & i & "," & ",B" & i & "," & ",C" & i & "," & ",D" & i & ")"
Here is the formula with escaped quotes to add the spaces (gives error):
set formula of row i of column 15 to"=CONCATENATE(A" & i & ","\" \" & ",B" & i & ","\" \" & ",C" & i & ","\" \" & ",D" & i & ")"
I get a sytax error on the first slash; Expected end of line etc. but found unknown token. I have a feeling I'm either missing a few sets of double quotes or I'm making this way more complicated than it needs to be. Any ideas? Should I be going about this differently?
Thanks in advance!
EDIT
Taking another look at it I think you have too many quotes when you use the \ character to escape the double quote. Instead of ","\" \" & ",B" try ",\" \",B" so your line would look like this:
set formula of row i of column 15 to "=CONCATENATE(A" & i & ",\" \",B" & i & ",\" \",C" & i & ",\" \",D" & i & ")"
In excel VBA you can double quote a double quote to get it to show up in a string like this:
"=CONCATENATE(A" & i & "," & """ """ & ",B" & i & "," & """ """ & ",C" & i & "," & """ """ & ",D" & i & ")"
Or you can try using ascii character for space which is Chr(32)