- •Оглавление
- •Introduction 2
- •Introducing Ms. Formula 10
- •Introduction Calc is a spread sheet -- what are those?
- •Open Sesame How to open a document
- •Save Me How to open a document
- •Close the Gates How to close a document
- •Introducing Ms. Formula An oversized calculator
- •Our first, real formula...
- •Average Joe The second formula
- •The time is now How to let Calc give you time
- •Extracting a given number of characters from a cells, counting from left
- •Extracting a given number of characters from a cells, counting from right
- •Extracting a given number characters, counting from the point you specify
- •How to create and use random numbers
- •How to look up values in a grid
- •How to round numbers
- •How to cut off decimals in an elegant way
- •How to sum only lines meeting your criteria
- •Vlookup(a1;b1:d100;3;0)
- •Vlookup(a1;b1:d100;3;0)
- •How to count characters in a cell or string
- •Formatting of text and cells How to change the appearance of the spreadsheet easily
- •DataPilot How to manipulate huge amounts of data easily
- •Charts How to create simple charts
How to create and use random numbers
Sometimes you might want to use random numbers. "Why on earth would I do that?", you might ask. I'll try to convince you to continue reading this article with a few examples...
If you want to try out a new spreadsheet, with a lot of formulas and formatting, and you need to fill it with numbers, any numbers, just to see if the mechanics of the spreadsheet works, you can use random numbers.
If you want to select a random number for testing purposes, you can use random numbers.
If you have a list of words in a foreign language you want to practice, and want to be tested in the words randomly, you can use random numbers.
If you want to test different scenarios, you can use random numbers.
I
have good news for you, my friend -- this is one of the easiest
formulas to use :-)
The syntax is as follows:
=RAND()
That's
it. There is actually nothing to put inside the parenthesis.
You
will get a new value each time you force a recalculation of the
spreadsheet or you enter any new calculation in the spreadsheet.
Go
to the next step to learn how to actually use
it.
Typing =RAND() into
any cell will give you a random number between 0 and 1.
OK,
say you want to vary the numbers between 0 and 1000, not just 1, what
to you do then? Yes, you guessed it, you can multiply the formula
with 1000. This way, since the result of the formula =RAND() is
between 0 and 1, you will get a random number between 0 and 1000. For
example:
=RAND()*1000
Using the same procedure; if you want the number to max out at 1 000 000, just mulitiply by 1 000 000, like this:
=RAND()*1000000
It's
not always very realistic that you'll need any number from 0 and
upwards, for example if you want random ages of persons, but only
adults.
In many countries people are regarded as adults at
the age of 18, so randomizing all numbers from 0 to, say maximum 100,
using this would not suffice:
=RAND()*100
Since you require the person to be adult, it simply wont work, because you risk ending up with both 3 and 7! Luckily it's not too difficult.
=RAND()*([max]-[min])+min
In this particulare example:
=RAND()*(100-18)+18
What happens here, is that you make sure that each value is at least 18, by adding 18 to any number you get. In addition you limit the maximum value by multiplying the result with 82 (100-18). Since we're adding 18 at the end of the formula, we make sure the random number, multiplied by 82, max out at 100. Please experiment a bit, until you get the hang of the logic.
=VLOOKUP()
How to look up values in a grid
=VLOOKUP() is
certainly one of the most powerful formulas in Calc. Simply put, you
will use =VLOOKUP() to
search for information in the leftmost column in an are you choose
and return the value in another column on the very same
line.
Everybody who works will large lists and use this
formula, will never, ever go back to the "old ways".
Personally I've worked with lists of several tens of thousand
lines.
Create
a list as shown here. Start with the headings in A1 and B1,
and the data just below. It is good practice to always have a header
in the columns, and keep the headers at the very first line of the
spreadsheet, as it makes everything more tidy which, in turn, makes
the table more predictable for formulas.
Go
to cell D3 and
enter "Name:".
In D4 you
enter "Amount:".
First
we'll enter the formula and see the result, then we'll take a closer
look at what's happening.
Go to E4 (the
cell immediately to the right where you entered "Amount:",
and enter: =VLOOKUP(E3;A1:B100;2;0)
NB! As
you can see here, we're using a semi-kolon; ";",
to separate inside the formula, your computer may be set up to use
comma instead, ",".
If so, correct the formula accordingly, everything else should be
just the same.
OK, nothing interesting has happened so
far, but you haven't done anything wrong! Now you can go to the next
step.
Now,
go to E3 (the
cell immediately to the right where you entered "Name:",
and enter: "Peter".
When you now press [Enter]
you should see the number "12"
in cell E4,
where you typed the formula.
What happened here is that
the formula tried to find the name you gave just above in the table
to the left. If Calc finds the correct name, it's instructed to give
you the corresponding amount.
Try experimenting with
typing different names, also try entering wrong names, just to see
what happens.
OK, now we'll start analyzing this formula.
It looks ugly, but it really isn't that horrible once we get to break
it up a bit.
Take another look at
it: =VLOOKUP(E3;A1:B100;2;0)
Now
we'll break it up: =VLOOKUP( what
to search for ; where
to search ; what
result to give ; accuracy )
what
to search for
This can
either be a value or, as here, a cell reference. In our example we
wanted to search for something related to "Peter", and we
got that that value from cell E3.
We would have excactly the same result if we replaced E3 with Peter,
like this:=VLOOKUP("Peter";A1:B100;2;0)
where
to search
This is the cell
reference to the table we want to work with. In this case it is the
area A1 to B100.
As you see, the names are given in the left column,
and the =VLOOKUP() formula
will always search in the left column of any table.
This is important.
The reason for typing B100, which is
obviously too far down, is to make sure that if we add more data
here, it will be included in the formula. Data enteret in
cell A101 and B101 will
not be considered by the formula. It is, by the way, not required
that you include the column headings, like I’ve done here.
what
result to give
If Calc is
able to find what
you wanted to search for, where
you wanted to search for it, you
need to specify exactly what information you want in return. In this
case, we specified that we wanted the related information from column
number 2 in
the table. Notice that the number is totally unrelated to the cell
reference itself -- of the same table was placed in the
columns F and G,
the reference number for the feedback would still be number 2,
as it refers to the table you defined in the green
area.
accuracy
OK,
to be more accurate it really means sorted or not sorted... If it
says "1",
it means that the list is sorted, and will give you the closest match
to what you searched for. You will probably never use that in you
entire life, so I suggest that you consequently use "0"
instead, which requires a perfect match. If it doesn't find a perfect
match, it will show an error message: "#N/A".
You
can also use the words "true"
or "false"
instead of, respectively, "1"
or "0",
with the exact same result -- but requires more typing! Sometimes
less i more :-) Then it would look like
this: =VLOOKUP(E3;A1:B100;2;false) Same
- same, but more to type.
I hope that you now can see some
of the potensial of this formula. Especially if you think BIG --
imagine having a huge list of 30 000 entries that you want to search!
That is not unrealistic, I've done it houndreds of times myself.
As
always, it is important to make sure that you lock the cell
references by adding "$"
to the cell references if you intend to copy the formula, for
instance like this: =VLOOKUP($E$3;$A$1:$B$100;2;0) This
way, if you copy the formula to the right, both the value
you want to search for and
the area in
which you want to search will
remain unchanged.
We will give you more examples of how to
use =VLOOKUP() later.
A
final advise; it is wise to define an area much longer than what you
need at the moment to make sure that you can accommodate more lines
of data (the green part
of the formula). If you ad more data to your table, it will
automatically be included in the area to search in the formula. If
you use a limited area, you will need to update the formula
manually.
First an example of
what happens if you make it fit only the amount of data that you
already have:
...then
an example of what happens if you make it a bit wider:
=ROUND()
