LibreOffice Calc: How to use a variable in a function/formula? - libreoffice

Before
After
I'm trying to dynamically fill a range of cells in a column based on a number in another cell.
So, fill x amount of cells with a value set in, say, E4. x is the value in cell E5.
If cell E4 = 25, fill the cells in the desired column below a certain point with "25" for x amount of rows. If E5 = 5, and the start point is A3, it would fill A3 through A8 with "25" or whatever desired string or formula.
For me, it's ="Layer " & ROW() - 2 and I want to fill every cell in that column to a range determined in E5. The amount of cells in that row would change dynamically with whatever is set in E5
Problem is, I can't find a way to set a variable and retrieve it's value in a single cell's forumula, and I can't use nested formulas either (SUM(Var1:E1) where Var1 is the string E2 or something like that)
In this case, starting at cell A3 = Layer 1, it would named each cell Layer 2, and then Layer 3, until the layer number matches the value in E5.
I also need to be able to count how many layers there are for a forumula in the next column that depends on the total number of layers (plus 1)
I don't really know a ton about Calc or Excel formulas, but they don't follow a convention that makes sense to me.
I would guess a nested sum function would work like: =SUM(SUM(A1:A5):A6) or =SUM((SUM(A1:A5)):A6) but it doesn't. And it doesn't seem like there is a way to set variables inside one cell's formula.
I also tried creating a string that would create the relevant cell reference and thus the right value, like =("E"&E1) which would create E5 if E1 was set to 5, but I can't use this value as a cell reference

To get the result shown in the images, enter =IF(ROW(D1)<=E$1;"Layer " & ROW(D1);"") in cell D3 and fill down to D10 by dragging the dark dot in the corner. Then change the value in E1 to see the difference.
The $ means do not change the following 1 in the reference when the formula is copied or filled elsewhere. Otherwise the formula references will be adjusted relative to the new location.
If I use =("E"&E1) to create "E5" based on the value in E1, I want to use the E5 as a cell reference and not a string.
That is what INDIRECT does.
=SUM(SUM(A1:A5):A6)
It should be =SUM(SUM(A1:A5);A6) instead. The first one is a range of cells, whereas the second gives an additional cell to include. You could also do for example =SUM(SUM(A1:A5);A6:A10).
I don't really understand why you would expect a : to work where the ; is. That would define a range that starts at the row of the result of the SUM and ends at a cell I suppose? Doesn't make sense to me. Maybe you intended something like =SUM(INDIRECT("A"&SUM(A1:A5));A6). Still I don't get why anyone would want to do that.
Spreadsheet formulas are different from programming languages. It may take some time to learn how to use them effectively. LibreOffice also has extensive support for macros if you need an actual programming language, although in most cases there is probably a better way to solve the problem without resorting to macros.

Related

Determining the lowest ever value of several ever changing cells

I have a row of three cells with constantly changing values. Cell 4 I wish to display the lowest value ever achieved by any one of the 3 cells. By definition the value of cell 4 can only go down, not up.
I am not sure there is a simple way to achieve this using only Calc built in functions, but attach an event macro would do the trick.
Say your 3 cells are: B1, B2, B3
Then in B4 =min(B1:B3)
Then put an event trigger on B4 using a code similar to this post.
The trigger code in Modify_modified should check if B4 is smaller than B5. If it is, then write the new min value in B5.

Indexing a grid with row and column number?

Very new to QGIS. I'm using it to analyse agricultural field microplots for research.
I need to give each field plot its own object which I've done so by using the "create grid" tool. But I need to assign a column and row number to each object in the attribute table to make it easier to sort the data. This should start in the bottom left (1:1) and ascend in row for objects above (2:1) and ascend in column for objects to the right (1:2).
I've orientated the grid to start in the bottom left and learned that by using #row_number, I can re-number the objects from 1 to the total number of objects. But I need to add column number and row number to the attribute table.
Is there a simple way of doing this?
I think the most accessible option here is using the field calculator to add two integer columns to the attribute table. For a rectilinear grid with cells_y cells in the y direction (24 in this case) the expressions are something like
floor(("id" - 1) / cells_y) + 1
where id is the attribute table column with the cell number (set automatically by Vector -> Research Tools -> Create grid or, in the OP's case, to #rownumber).
For the y index it's
cells_y + 1 - if(("id" % cells_y) = 0, cells_y, "id" % cells_y)
This is for the ones based indexing asked for here; remove the + 1 bits for zero-based. Similarly, subtracting (as is done with y here) or not subtracting (x here) the modulus part flips the directions in which the cells are numbered. This approach can also be used in PyQGIS.
There's a few grid plugins for QGIS and several similar StackOverflow questions (like this one) which may also be of interest.

Excel, Unable to change the number format

I was wondering if somebody could help me with this one. It’s probably so simple, but its got me at a loss.
I have a Excel spreadsheet looking like this
Basically it’s a simple if statement if A1 = 10 then B1 will display 600, if not it will display a 0. It works ……but I can not format the number in B1, I right click Format cell, number, and select currency with 2 decimal places. No change . Colour, alignment, Boarder and fill works, its just the number type will not. B1 will feed other cells to workout a formulas. I need it in a currency format.
Does anyone know the answer to this.
Thanks in advance
David
Use the integers instead of strings. Excel interprets your strings as... well... strings, and not numbers. Change your strings to numbers like this:
=IF(A1=10,600,0)
This should work and it should justify right again.

Excel - Circular References (all values change when one changes)

I have several products. Each product has four different dimensions, and they're each dependent on one another. Meaning, if I know one, I know the rest of them.
Each product is different, so the way that they depend on each other is different. But the fact of the matter doesn't change-if i know one value of any dimension - i know the rest.
I'd like to be able to just type in a value into the cell and have excel automatically populate the rest for me.
It's too tedious with VBA and i'd like it to be automatic upon entry, and not have to have someone click a button. Just when you type it in.
Thank you
What you want is impossible without VBA. I offer you a simple method instead:
There's an infinite amount of ways to do that. I want some SE points. So, I will just post the first method that comes to mind.
Have two rows:
Input: [Height] [Width] [Length]
Result: [Height] [Width] [Length]
(the above will have the following shape:)
A1 B1 C1 D1
A2 B2 C2 D2
You don't touch the result row. You input into the blank input rows and then the result rows check for the input and calculate accordingly.
In the result row, you will use "nested if", NOT(ISBLANK(A1)) and your own calculation method. Here's an example of nested if: =IF(NOT(ISBLANK(A1)),A1*2,IF(NOT(ISBLANK(B1)),B1*3,IF(NOT(ISBLANK(C1)),C1*4, IF(NOT(ISBLANK(D1)),D1*5))))
Each cell in the result row will require a different calculation formula.
I suggest you open a brand new excel worksheet and paste the above formula into cell A2. Then, type a number into either A1, B1, C1 or D1 and notice what happens in cell A2.
Also, please note the above formula has not been "fixed". If you drag the formula, excel will try to adjust it and things can go bad.

MATLAB UITABLE AND FORMAT OPTIONS

I have followed many posts about format of numbers in Matlab. Now I have set up Matlab uitable in such a way that one can fill the table cell by cell. I want the first column to maintain numbers up to say 12 digits, so I set the format to longG. Matlab uitable is refusing to accept my format and the frustrating part is, in the command window all digits are shown even up to 15 digits with format longG option. This is the sample;
colNam={'W','X','Y','Z'};
t=uitable('ColumnName',colNam,'Data',zeros(4),'ColumnEditable',...
[true true true true],'ColumnWidth',{150,'auto'},...
'ColumnFormat',{'numeric'});
set(t,'ColumnFormat',{'longG'});
I know of sprintf and fprintf as has been explained elsewhere. But please what we are refusing to realize is that, these change the class of the number from double to char. What if you want to set up the table so that it increases by 1 dynamically (credits to thewaywewalk)? We can't add double to char for this purpose. Please this is frustrating. Any suggestions? Thank you.
There is no such ColumnFormat property called "longG", where dis you see that ?
You have the possibility of manipulating the Java part of the Uitable in order to really display numeric values... but I think the best (and easiest) way is to use char.
If you want to increase the values, just convert it first to numeric, increase, then convert it back.
Based on John's suggestion, I put up this code and I could set the table to accept any number of digits.
f=figure;
dat=[101100220001;101100220002;101100220003;101100220004;101100220005];
colNam={'W'};
t=uitable('ColumnName',colNam,'Data',dat,'ColumnEditable',...
[true],'ColumnWidth',{150},'pos',[5 250 200 120]);
newdat=get(t,'Data');
newdat=strtrim(cellstr(num2str(newdat))); %Convert data to cell array of strings
tt=uitable('ColumnName',colNam,'Data',newdat,'pos',[300 250 200 120]);