4.5 Using Complex Macros with Real-Life Problems Part 3
8 hours 33 minutes
So in this macro I have already created, which is called Imperial to Metric. We have a code to convert thes
Ah ah! Units
on and the amounts from imperial to metric. So what's you get the code
and we have two counters here at first define. So we have counter one which will guide us through the rows in
the recipe and the second counter, which will take us through the roads in comparison chart.
so we set the first counter to three because this is the first throw. And then we started the doo boo, and first thing we do is set counter to one,
and then we go to find the equivalent unit.
So again, a do loop, which will take us through all ingredients, regardless of how many off them there are. So in this point, we have just four of them. But it might be that we had something in the future
and we have a questions. If she eats comparison chart, range a encounter too. So that means that way. Look. Att? The first row row in comparison sheet in range, eh
in a recipe cell C
And this is three Because this is the first line of ingredients.
Then we go to change value to metrics. So we
that will you
What we found is the equivalent
unit in metric units.
basically we look att, this number that we
that represents the difference because in this case, his ounces and grams
and maybe multiply it with
the amount of chances. And then what we also do is we changed the unit name to metric. So we look att
the own see
C three is now equal What is in comparison chart in the one
and we end. If so, if it's not
or if it is, it doesn't matter. It go to second counter and we go through all this case four units
uh, in compares a sheet
and then we
closed the loop by loop until and we look it that when the first entry in comparison chart in in cold a is now blank space
and we when we closed this loop,
we go. So we always go through all ingredients because we don't know which one is going to be,
uh, the one we're looking for And it really doesn't matter if we found it and we go again, it won't change again because we found that unit has only one occurrences in this range. And we continue
with the whole thing.
again for next row. So we now go to next four ingredients. We increase the counter toe by one and we look in a loop until so again, If we reached instructions,
then we stop
and we end this 17. So this is how we change imperial to metric.
Uh, and let's not do this at this point.
and close this one.
Close this one.
So let's go to make Rose
and type the new name. So metric
Imperial check. If there are no spaces, let's create it.
And we have this sub here
let's copy the content of the other one there.
So let's copy
this. So we have again
counters contraband and count to do it again. Started counting tree.
And now we look att comparison charts, but not any more in the range.
Be three but a three. But in B three, So we're looking now in a column with metric units.
And if it's equal
then we change
value to metric. So again, we're changing range B.
we're dividing it.
So we have the same number.
But now we're dividing it.
Sorry, we're dividing this
with the value from from comparison chart
and we're changing units
and we're no longer looking at the range. Beware The metric units are because we are metric units. We're going to change it to
and then we're still looping until
no more entries in comparison chart,
and then we're doing the same thing again and loping until we
Uh, in, uh,
and this is it deserved. The only change is so we're going to save it now.
this way we have created to several teens, which we're going to call
from the one that we're going to create, which is going to
which would be here already created, the one that's called decide.
So let's close this. Let's make short break
in next video