I have a text box in PBI whose title is set to a measure value as shown below:
dense test =
var seperator = "|"
var a = "some set of value:"
var a1 = 1100
var a2 = 240000
var b = "some other set of value:"
var b1 = 2300
var b2 = 15000
var alltogether =
a & a1 & seperator & a2 & UNICHAR(10) &
b & b1 & seperator & b2
RETURN alltogether
word wrap is off
title is set to a function -> the measure value
alignment = left
what I'm struggling with is I cannot get the pipe seperator to align I've tried padding with REPT() function but it seems as though the textbox decides arbitrarily how much space to add after each variable.
dense test rept =
var seperator = "|"
var a = "some set of value:"
var a1 = 1100
var a2 = 240000
var b = "some other set of value:"
var b1 = 2300
var b2 = 15000
var alltogether =
a & REPT(UNICHAR(127),25 - LEN(a)) & a1 & seperator & a2 & UNICHAR(10) &
b & REPT(UNICHAR(127),25 - LEN(b)) & b1 & seperator & b2
RETURN alltogether
Results below:
Related
I need to get the NumberFormat from an excel file (appr. 3000 lines) and I wrote a simple Script which copy it from column A to column C each row by row. I tried to use this script with Power Automate after 10 minutes.
I already set the timeout on 60 minutes, but it seems that my tenant configuration abort it always after exactly 10 minutes.
Here is my script:
function main(workbook: ExcelScript.Workbook) {
let sheet = workbook.getWorksheets()[0]
let range = sheet.getUsedRange(true);
let rows = range.getUsedRange(true).getRowCount();
let cols = range.getUsedRange(true).getColumnCount();
for (let row = 2; row <= rows; row++) {
sheet.getRange("C" + row).setValue(sheet.getRange("A" + row).getNumberFormat())
}
}
Is there an easier way to copy the NumberFormat from one column to another and does anybody know a better way?
Please make sure when you ask these questions to put the Office-Scripts tag since this is Office Scripts. You don't need to loop to achieve this. You can use getNumberFormats() like in the code below.
function main(workbook: ExcelScript.Workbook) {
let sheet = workbook.getWorksheets()[0];
let rowCount = sheet.getUsedRange(true).getRowCount();
let numFormats = sheet.getRange("A1:A" + rowCount).getNumberFormats();
let newRng = sheet.getRange("C1:C" + numFormats.length).setValues(numFormats);
}
EDIT 4/23/21
If you just want to get the indent levels, then you could just insert this formula in column C rather than getting the number formats.
=IFERROR(LET(indentLevel,FIND("[",FILTER(A:A,A:A<>""),1),SWITCH(indentLevel,4,1,6,2,8,3,10,4,12,5)),"Other Formula Here")
Here is the Office Scripts
function main(workbook: ExcelScript.Workbook) {
let sheet = workbook.getWorksheet("Sheet1");
sheet.getRange("C1")
.setFormulaLocal("=IFERROR(LET(indentLevel,FIND(\"[\",FILTER(A:A,A:A<>\"\"),1),SWITCH(indentLevel,4,1,6,2,8,3,10,4,12,5)),\"Other Formula Here\")");
}
Here is my VBA code where I use a for loop:
Sub GetHierachyParents()
Set appExcel = holeAnwendung("Excel.Application")
Set wbkExcel = appExcel.Workbooks.Open("C:\impport.xlsx")
Set wksExcel = wbkExcel.Sheets("Hierachy")
countRows = wksExcel.Range("A1").End(xlDown).Row
For i = 2 To countRows
Node = 0
If (Len(wksExcel.Range("A" & i).NumberFormat) - Len(Replace(wksExcel.Range("A" & i).NumberFormat, "[-]", "")) > 0) Then
IndentLevel = (Len(wksExcel.Range("A" & i).NumberFormat) - Len(Replace(wksExcel.Range("A" & i).NumberFormat, " ", "")) - 1) / 2
Node = -1
Else
IndentLevel = (Len(wksExcel.Range("A" & i).NumberFormat) - Len(Replace(wksExcel.Range("A" & i).NumberFormat, " ", "")) - 5) / 2
Node = 0
End If
sql = "INSERT INTO impTemp0 (F1, F2, F3, F4) VALUES ('" & wksExcel.Range("A" & i) & "', '" & Replace(wksExcel.Range("B" & i), "'", "") & "', " & IndentLevel & ", " & Node & ")"
CurrentDb.Execute sql
Next i
CurrentDb.Execute "UPDATE [impTemp0] SET Parent = DMAX('id','[impTemp0]','[impTemp0].id<' & [impTemp0].id & ' AND [impTemp0].Level=' & [impTemp0].Level-1 & '')"
End Sub
And here is an example for the first 8 rows:
" [-] "#
" [-] "#
" [-] "#
" [-] "#
" [-] "#
" "#
I have hundreds of rows data in vertical columns. I want to rearrange it in rows.....
Image is attached what I want to achieve.....
your valuable Help is appreciated...
A19 = 2
A20 = A19 + 3
B19 = =INDIRECT("A" & $A19)
C19 = =INDIRECT("B" & $A19)
D19 = =INDIRECT("C" & $A19)
E19 = =INDIRECT("C" & $A19 + 1)
F19 = =INDIRECT("C" & $A19 + 2)
G19 = =INDIRECT("D" & $A19)
H19 = =INDIRECT("D" & $A19 + 1)
I19 = =INDIRECT("D" & $A19 + 2)
J19 = =INDIRECT("E" & $A19)
K19 = =INDIRECT("E" & $A19 + 1)
L19 = =INDIRECT("E" & $A19 + 2)
... now fill down as far as you need but be careful filling down column A from A19, you need to fill down from A20.
You can make it more dynamic by putting the column letters above your headers if you want but that's up to you.
There are a few ways to do what you want and you may find an easier way.
enter image description here
Check Above Sample Pic
Could someone give me some pointers on how to write this formula right?
Sub WriteFormulaTextAndNumbersDependentOnI()
Dim xNumber As Integer
xNumber = InputBox ("Choose I")
For I = 1 To xNumber
Worksheets("Sheet1").Cells(1, 1 + I).Formula = "= & 2,10 + 0,01 * (I - 1)'" & Sheets(I + 1).Name & "'!B12"
Next I
End Sub
The point here is to write a name in different cells, with a calculated number (2.10 + 0.01*(I - 1)) and text from another sheet:
Lets say we have in Sheet2:
B12 = Hello World
Lets say we have in Sheet3:
B12 = You are cool!
We should then get in Sheet1:
I = 1 would give a value/text in cell B2, with the value/text: "2.10+0.01*(1-1) B12" = "2.10 Hello World"
I = 2 would give a value/text in cell C2, with the value/text: "2.10+0.01*(2-1) B12" = "2.11 You are cool!"
An so on.
Any suggestions?
Appreciate any suggestions
//GingerBoy
use:
Concatenate() worksheet function to mix numbers and text in the same string
Text() worksheet function to format a number to a string
as follows:
Worksheets("Sheet1").Cells(2, 1 + I).Formula = "=concatenate(TEXT(2.10 + 0.01*(" & I & "-1),""0.00""), "" "", " & Sheets(I + 1).Name & "!B12)"
see that:
I used Cells(2, 1 + I) to write in in B2, C2 ... as per your narrative
I used dots (.) as decimal separator: you may want to change all dots into commas as per your decimal separator conventions
Cell A2 contains value "25-86".
I need cell B2 to have value "AJ 2586%"
This code reveals Syntax error:
Range("B2").Value = "AJ & Left(Range("A2"), 2) & Right(Range("A2"), 2) & %"
If I write it like that
Range("B2").Value = "AJ & Left(A2, 2) & Right(A2, 2) & %"
The functions Left and Right treat "A2" as string.
How could I extract a part of text from the cell and enter it in another cell?
The issue is that everything between the " " defines a string.
You can type your code like this:
Range("B2").Value = "AJ " & Left(Range("A2"), 2) & Right(Range("A2"), 2) & "%"
The following formula will return the value as a real percentage that you can use in calculations.
It just removes the - from the figure.
=SUBSTITUTE(A2,"-","")/100
Initially it will display the value as 25.86.
When you apply the custom number format of:
\AJ 0%
It will then display as AJ 2586%.
If that formula is in A1 then =A1/2 will return AJ 1293%.
Edit:
Just realised you want it in VBA:
Range("B2") = Replace(Range("A2"), "-", "") / 100
Range("B2").NumberFormat = "\AJ 0%"
Or, if you just want it as text:
Range("B2") = "AJ " & Replace(Range("A2"), "-", "") & "%"
Range("B2").Value = "AJ " + Left(Range("A2"), 2) + Right(Range("A2"), 2) + "%"
Indent code 4 spaces in order for it to be in the correct format
I would like to group data in my Excel in a automatic way (by using a macro)
For example, in my column A, I have fields tuck as this:
in A1 I have " 1.0.1",
in A2 " 1.0.3",
in A3 " 1.0.5",
in A4 " 1.1.1",
in A5 " 1.1.2".
I would like to group these data so as to have two groups: 1.0 (packaging A1, A2 and A3) and 1.1 (packaging A4 and A5).
The problem is that the data which can vary (addition of one given 1.0.7 for example which it will be necessary to group(include) in 1.0)
So, it would be necessary to read all the fields of the column A and to make a regroupage by comparing the first 3 characters of every fields, and so to group what is identical.
It is possible to make that in Visual Basic ?
sub regrouper()
Worksheets.Add.Name="group1"
Worksheets.Add.Name="group2"
Dim g1Row As Integer
Dim g2Row As Integer
Dim splitter(0 to 4) As String
g1Row = g2Row = 2
For Each cell in Worksheets(1).Range("A1:A" & Range("A65536").End(xlup).Row)
splitter = Split(cell.text, ".")
If splitter(1) = 0 then
Worksheets("group1").Range("A" & g1Row).Value = cell.Value
g1Row = g1Row + 1
ElseIf splitter(1) = 1 then
Worksheets("group2").Range("A" & g2Row).Value = cell.Value
g2Row = g2Row + 1
Else
MsgBox("data not in group 1 or 2")
End If
Next cell
End Sub
not tested but should get you a little closer