+ Reply to Thread
Results 1 to 6 of 6

autofill numbers

  1. #1
    Registered User
    Join Date
    03-25-2012
    Location
    JAPAN
    MS-Off Ver
    Excel 2003
    Posts
    5

    autofill numbers

    hi,

    I am totally new to vba, and need help with the code.

    I have 20 numbers need to automatically fill in column a and column b in the way of:
    A1: 1 B1: 1
    A2: 1 B2: 2
    A3: 1 B3: 3
    ............
    A20:2 B20: 20
    A21:2 B21: 1
    A22:2 B22: 2
    A23:2 B23:3
    A? :2 B? : 20
    ...........

    till
    A? :20 B?:1
    A? :20 B?:2
    A? :20 B?:3
    A? :20 B?:20

    for the extension of this, I also need to fill in column C, so the idea will be as below:
    A1: 1 B1: 2 C1:1
    A2: 1 B2: 2 C2:2
    A3: 1 B3: 2 C3:3
    .........................
    A20:1 B20:2 C20:20
    A21:1 B21:3 C21: 1
    A22:1 B22:3 C21: 2
    A23:1 B23:3 C21: 3
    --------------------
    A? :1 B?: 3 C?: 20
    .........................
    till
    .........................
    A? : 20 B?: 20 C?:18
    A? : 20 B?: 20 C?:19
    A? : 20 B?: 20 C?:20

    Please help, thank you!
    Last edited by ce7; 07-30-2014 at 11:37 PM. Reason: not funished yet

  2. #2
    Registered User
    Join Date
    07-17-2014
    Location
    Turkey
    MS-Off Ver
    2003
    Posts
    85

    Re: autofill numbers

    If you can explain to processing logic I can assist you . Even, you can load a file which filled by you as manual.

  3. #3
    Administrator FDibbins's Avatar
    Join Date
    12-29-2011
    Location
    Duncansville, PA USA
    MS-Off Ver
    Excel 7/10/13/16/365 (PC ver 2310)
    Posts
    52,946

    Re: autofill numbers

    The logic is pretty simple.

    Column A stays the same value up to multiples of 20 rows...
    =INT(ROW()/20)+1

    Column B increases until a row multiple of 20 is found, then restarts
    use a seed of 1 on B1
    B2, copied down...
    =IF(A2=A1,B1+1,1)

    However, it looks like you keep increasing past the 20th row in column B, but not column A?

    Perhaps you need this in column A?
    =INT(ROW()/21)+1
    1. Use code tags for VBA. [code] Your Code [/code] (or use the # button)
    2. If your question is resolved, mark it SOLVED using the thread tools
    3. Click on the star if you think someone helped you

    Regards
    Ford

  4. #4
    Registered User
    Join Date
    03-25-2012
    Location
    JAPAN
    MS-Off Ver
    Excel 2003
    Posts
    5

    Re: autofill numbers

    can you please give me example code, thanks!

  5. #5
    Administrator FDibbins's Avatar
    Join Date
    12-29-2011
    Location
    Duncansville, PA USA
    MS-Off Ver
    Excel 7/10/13/16/365 (PC ver 2310)
    Posts
    52,946

    Re: autofill numbers

    I did, in post #3

    Column A stays the same value up to multiples of 20 rows...
    =INT(ROW()/20)+1
    Column B increases until a row multiple of 20 is found, then restarts
    use a seed of 1 on B1
    B2, copied down...
    =IF(A2=A1,B1+1,1)

  6. #6
    Forum Expert martindwilson's Avatar
    Join Date
    06-23-2007
    Location
    London,England
    MS-Off Ver
    office 97 ,2007
    Posts
    19,320

    Re: autofill numbers

    looks like a few typos in the example as op says 20 numbers

    a1
    =CEILING(ROWS($1:1)/20,1)
    b1
    =MOD(ROWS($1:1)-1,20)+1
    for the second bit including col c i cant see whats required
    "Unless otherwise stated all my comments are directed at OP"

    Mojito connoisseur and now happily retired
    where does code go ?
    look here
    how to insert code

    how to enter array formula

    why use -- in sumproduct
    recommended reading
    wiki Mojito

    how to say no convincingly

    most important thing you need
    Martin Wilson: SPV
    and RSMBC

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. How do I autofill every OTHER row with ascending numbers
    By aimeecrystalaid in forum Excel Formulas & Functions
    Replies: 6
    Last Post: 02-05-2014, 08:14 PM
  2. How to autofill numbers with letters
    By tantan in forum Excel General
    Replies: 4
    Last Post: 02-13-2013, 05:19 AM
  3. autofill without the sequential numbers
    By lancejularbal in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 06-12-2010, 12:21 PM
  4. Autofill numbers using Macro
    By kamalthakur in forum Excel Programming / VBA / Macros
    Replies: 25
    Last Post: 01-21-2010, 04:05 PM
  5. Autofill numbers in a range
    By jwilliams84 in forum Excel General
    Replies: 7
    Last Post: 07-31-2009, 11:06 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1