Results 1 to 8 of 8

Thread: [RESOLVED] Excel - Autofill Multiplication table type ranges.

  1. #1

    Thread Starter
    PowerPoster
    Join Date
    Oct 2002
    Location
    British Columbia
    Posts
    9,758

    Resolved [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

  2. #2
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    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

  3. #3
    Head Hunted anhn's Avatar
    Join Date
    Aug 2007
    Location
    Australia
    Posts
    3,669

    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
    • Don't forget to use [CODE]your code here[/CODE] when posting code
    • If your question was answered please use Thread Tools to mark your thread [RESOLVED]
    • Don't forget to RATE helpful posts

    • Baby Steps a guided tour
    • IsDigits() and IsNumber() functions • Wichmann-Hill Random() function • >> and << functions for VB • CopyFileByChunk

  4. #4
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: Excel - Autofill Multiplication table type ranges.

    a different code, same result
    vb Code:
    1. Range("b1") = 20
    2. Range("c1") = 22
    3. Range("d1") = 24
    4. Range("b1:c1").AutoFill Range("b1:v1")
    5. Range("a2") = 100
    6. Range("a3") = 125
    7. Range("a4") = 150
    8. Range("a2:a4").AutoFill Range("a2:a38")
    9. 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

  5. #5
    Head Hunted anhn's Avatar
    Join Date
    Aug 2007
    Location
    Australia
    Posts
    3,669

    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
    • Don't forget to use [CODE]your code here[/CODE] when posting code
    • If your question was answered please use Thread Tools to mark your thread [RESOLVED]
    • Don't forget to RATE helpful posts

    • Baby Steps a guided tour
    • IsDigits() and IsNumber() functions • Wichmann-Hill Random() function • >> and << functions for VB • CopyFileByChunk

  6. #6
    New Member
    Join Date
    Nov 2009
    Posts
    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.
    ______________
    Calcul taux d'interet immobilier meilleur banque | Taux d interets legal emprunt actuel | Calcul taux d'interet immobilier

  7. #7
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    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

  8. #8

    Thread Starter
    PowerPoster
    Join Date
    Oct 2002
    Location
    British Columbia
    Posts
    9,758

    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
  •  



Click Here to Expand Forum to Full Width