|
-
Nov 10th, 2009, 04:06 PM
#1
[RESOLVED] Excel - Autofill Multiplication table type ranges.
Is there a quick way to autofill the following sample sheet
Code:
A B C D V
1 20 22 24 ... 60
2 100 =A2*B1 =A2*C1
3 125 =A3*B1 =A3*C1
4 150 =A4*B1
.
.
.
10000
-
Nov 11th, 2009, 03:51 AM
#2
Re: Excel - Autofill Multiplication table type ranges.
you can play around with this code
range("b1:d1").AutoFill range("b1:v1")
where b1 to d1 has the initial data (20,22,24) already filled
same for column A
try like
range("b2:v" & lastrow).formula = "=$a2* b$1"
to fill the formulas for the entire range
if you want the complete code let me know, i wrote it already
Last edited by westconn1; Nov 11th, 2009 at 04:05 AM.
i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next
dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part
come back and mark your original post as resolved if your problem is fixed
pete
-
Nov 11th, 2009, 06:05 AM
#3
Re: Excel - Autofill Multiplication table type ranges.
Try this:
Code:
With Sheet1
.[A2] = 100
.[A3:A398].FormulaR1C1 = "=R[-1]C+25"
.[B1] = 20
.[C1:V1].FormulaR1C1 = "=RC[-1]+2"
.[B2:V398].FormulaR1C1 = "=RC1*R1C"
End With
-
Nov 11th, 2009, 03:02 PM
#4
Re: Excel - Autofill Multiplication table type ranges.
a different code, same result
vb Code:
Range("b1") = 20 Range("c1") = 22 Range("d1") = 24 Range("b1:c1").AutoFill Range("b1:v1") Range("a2") = 100 Range("a3") = 125 Range("a4") = 150 Range("a2:a4").AutoFill Range("a2:a38") Range("B2:v38").Formula = "=$a2* b$1"
i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next
dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part
come back and mark your original post as resolved if your problem is fixed
pete
-
Nov 11th, 2009, 06:02 PM
#5
Re: Excel - Autofill Multiplication table type ranges.
That is very good pete. But you have 2 extra lines (3. and 7.) that are not required.
Code:
[B1] = 20
[C1] = 22
[B1:C1].AutoFill [B1:V1]
[A2] = 100
[A3] = 125
[A2:A3].AutoFill [A2:A398]
[B2:V398].Formula = "=$A2*B$1"
Another way that use an array and 3 ForNext loops. The code is longer but faster:
Code:
Dim r As Long, c As Long
Dim ar(1 To 398, 1 To 22)
For c = 2 To 22
ar(1, c) = 20 + 2 * (c - 2)
Next
For r = 2 To 398
ar(r, 1) = 100 + 25 * (r - 2)
For c = 2 To 22
ar(r, c) = ar(r, 1) * ar(1, c)
Next
Next
[A1].Resize(398, 22) = ar
-
Nov 11th, 2009, 08:35 PM
#6
New Member
i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
______________
Calcul taux d'interet immobilier meilleur banque | Taux d interets legal emprunt actuel | Calcul taux d'interet immobilier
-
Nov 11th, 2009, 09:00 PM
#7
Re: Excel - Autofill Multiplication table type ranges.
That is very good pete. But you have 2 extra lines (3. and 7.) that are not required.
i always like 3 cells for autofill, in some cases 2 can be ambiguous, as you say probably not required here
i really like the resize for filling the range from array, much nicer than using offsets to the ubounds
i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next
dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part
come back and mark your original post as resolved if your problem is fixed
pete
-
Nov 12th, 2009, 01:03 AM
#8
Re: Excel - Autofill Multiplication table type ranges.
Thanks for the replies.
I actually searched for "multiplication table" in Excel help and was surprised to get a few hits. One topic was called "Create a Multiplication Table", go figure. It really pays to RTFM. Following is the information from the Help file.
Code:
A multiplication table is a two-variable data table.
Set up a worksheet with the following structure.
A
1 1
2 1
3 =A1*A2
Enter a row of values from B3 to the right. For example, 1 through 10.
Enter a column of values from A4 down. For example, 1 through 10.
Select all cells in the range except cells A1 and A2.
On the Data menu, click Table.
In the Row input cell box, enter A1.
In the Column input cell box, enter A2.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|