SOLVED

How to multiply two Integer variables within another and then use it to count rows?

Copper Contributor

I made a macro that serves me to subdivide an invoice that in turn can have one or more regions (rows) that divide the products by activity and establishment. You can also have a single row. What is sought is that if one wants to pay that invoice in turn divided into several checks with different expiration dates, this whole process is done through a macro automatically. The number of checks in which the invoice is to be divided is consulted by the user through an inputbox that takes the data to cell B1 of another page, in cell F1 with the function will count (), the ranks are counted in which The invoice was subdivided. Therefore, these two values I need to multiply so that, at the end of the macro (the rest of the process works perfectly), at the base where the data is hit by overwriting the original invoice with the division into as many checks as you wanted the user. My problem is that I need to erase the content of the first blank cell under the last date of the last check. And, although I define three integer variables
Dim ranks as integer (row number in which the invoice was originally subdivided)
Dim numch as integer (number of checks in which you want to divide the invoice)
DIM Result As Integer (result of the multiplication of rows * numch)
Then later I define them as:
Range ("B1") = numch
Range ("F1") = Rows
Result = (numch * rows)
For some reason, when I indicate that you descend from the cell it activates the amount of rows that returns result:
Activecell.offset (result, 0) .range ("A1"). Select
But it always stays in the original active cell, that is, the first date of the first row in which the invoice was divided ...
So I deduce that I am making the use of the variables wrong or how they multiply.
If anyone has any suggestion, I appreciate it, more than all for taking the time to read this long text that I hope is understood.
Greetings to the community and thanks!

2 Replies
best response confirmed by Hans Vogelaar (MVP)
Solution
I don't understand all that you are doing but highly recommend you use the 'Immediate' window (you can toggle showing it using Ctrl-G or under the View menu). For example:
Print activecell.address
$B$9
Print activecell.offset(2,2).address
$D$11
Print activecell.offset(2,2).range("A1").address
$D$11
Print activecell.offset(2,2).range("B2").address
$E$12
so basically my point here is that the .range("A1") is not extending or moving your range but rather acting like offset but since it is "A1" it is like offset of 0,0
hope that is helpful
1 best response

Accepted Solutions
best response confirmed by Hans Vogelaar (MVP)
Solution
I don't understand all that you are doing but highly recommend you use the 'Immediate' window (you can toggle showing it using Ctrl-G or under the View menu). For example:
Print activecell.address
$B$9
Print activecell.offset(2,2).address
$D$11
Print activecell.offset(2,2).range("A1").address
$D$11
Print activecell.offset(2,2).range("B2").address
$E$12
so basically my point here is that the .range("A1") is not extending or moving your range but rather acting like offset but since it is "A1" it is like offset of 0,0
hope that is helpful

View solution in original post