M
M
Mr Crabbz2014-05-15 23:18:39
Macros
Mr Crabbz, 2014-05-15 23:18:39

How to record and use such a macro in Excel?

Greetings!
There are two tables linked by certain functions.
What functions are not particularly important now, I did this for an example:
The second table takes data from the first row of the first table, sums them up in a cunning way and places them in the first line. Further, in the second table, the second line takes data from the second line of the first table, plus the first line of the second table (which is above it). Etc.
The task is as follows - to stretch the rows of the second table from the last filled row of the second table to the last row of the first table, taking into account all these functions using a macro. You ask - "why drag it with a macro, if you can just select the last line of the second table and drag it down with the mouse." The problem is that there are more than ten thousand rows of the first table in the "combat" task (a large database). You need to record a macro in order to press it and go away to drink coffee for 20 minutes, until it stretches and recalculates everything.
53bfecff05bd4dfba21ec1ca9440bfa6.png
Broach manually works with a bang - the data is considered correctly. But you need a macro, because the amount of time will be very large.
Problem following: it is impossible to record a macro in any way. First, I try normal recording and playback - it seems to be writing, but it is played back with hard-coded cell and line addresses (from 22 to 40). If in the first table, after these manipulations, add another n-th number of lines with data, the macro still pulls lines from 22 to 40. Of course
, you need to enable relative addressing. We turn it on here:
e6dfccdfa5de41d29444d9d96445e823.png
"It should work" - you say. But it was not there! After recording and playing the macro, we get an error:
e3b8c62889ad4e7f9f36f15e524a31f0.png
Debug window:
087fee9bfd6e434793fc2444a2bcc917.png
Here I have a stupor - I don't know VBA =(.

Answer the question

In order to leave comments, you need to log in

3 answer(s)
R
rosperitus, 2014-05-16
@rosperitus

D4 is the source of formulas and data, and D5: D35 is the range where you want to stretch
In general, it is usually enough to copy a line (range) with formulas (formats / data), and then select the range you need to pull and paste

Y
Yuri Lobanov, 2014-05-19
@iiil

In the macro, you need to determine the number of rows in the first table and fill the second table with formulas for the same number of rows. But it’s not clear at all, you fill in the second table to the end so that it doesn’t display zeros - check for an empty value, for example, the sum of the first two is considered in the third column, but only if there are numbers:
=IF(A1<>''; A1+B1;'')
And stretch the entire table 2 to the end, you can do it once. Well, or as he said - write a macro. Do not own vba - welcome to the freelance exchange, working as a trifle.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question