Consulting

Results 1 to 4 of 4

Thread: How to fill the number in the cells.

  1. #1
    VBAX Contributor
    Joined
    Nov 2009
    Posts
    114
    Location

    How to fill the number in the cells.

    Any code can make the following pattern? Thanks!


    * A B C D E
    1 1 2 3 4 5
    2 2 3 4 5 1
    3 3 4 5 1 2
    4 4 5 1 2 3
    5 5 1 2 3 4

  2. #2
    My first try

    [VBA]Cells(1, 1).Resize(, 6).Value = Array(Chr(42), "A", "B", "C", "D", "E")
    Cells(2, 1).Resize(, 6).Value = Array(1, 1, 2, 3, 4, 5)
    Cells(3, 1).Resize(, 6).Value = Array(2, 2, 3, 4, 5, 1)
    Cells(4, 1).Resize(, 6).Value = Array(3, 3, 4, 5, 1, 2)
    Cells(5, 1).Resize(, 6).Value = Array(4, 4, 5, 1, 2, 3)
    Cells(6, 1).Resize(, 6).Value = Array(5, 5, 1, 2, 3, 4)[/VBA]
    Feedback is the best way for me to learn


    Follow the Armies

  3. #3
    Mac Moderator VBAX Guru mikerickson's Avatar
    Joined
    May 2007
    Location
    Davis CA
    Posts
    2,778
    You could put =MOD(ROW()+COLUMN()-2, 5)+1 in A1 and drag down and right

  4. #4
    Quote Originally Posted by mikerickson
    You could put =MOD(ROW()+COLUMN()-2, 5)+1 in A1 and drag down and right
    wow man how did you find the logical pattern here?

    If you don't wanna drag and using mikerickson brilliant idea then

    [VBA]Range("A1:E5").FormulaR1C1 = "=MOD(ROW()+COLUMN()-2, 5)+1"[/VBA]
    Feedback is the best way for me to learn


    Follow the Armies

Posting Permissions

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