+ Reply to Thread
Results 1 to 2 of 2

Incrementing values in cells

Hybrid View

  1. #1
    Registered User
    Join Date
    09-10-2009
    Location
    London, England
    MS-Off Ver
    Excel 2003
    Posts
    6

    Incrementing values in cells

    Hi,

    I have a worksheet where cell A1, B1, C1, D1, etc...(through to U1) each have a value of 1.

    I need a routine that increments the value of A1, but when A1 reaches 3 it should re-set A1 to 1 and increment B1 etc....

    1 1 1 1 then
    2 1 1 1
    3 1 1 1
    1 2 1 1
    2 2 1 1
    3 2 1 1
    1 3 1 1 etc

    Probably not the best explanation ever - It's basically counting columns of units, tens, hundreds etc, but in base 3

    Thanks

  2. #2
    Forum Contributor
    Join Date
    04-16-2009
    Location
    Dorset, UK
    MS-Off Ver
    Office 2003, Office 2007
    Posts
    131

    Re: Incrementing values in cells

    You might find it easier to work down rather than across. In each column you want (3^(column number -1)) of ones, then the same of twos, then of threes. This is then repeated. Only the last column only loops through once.

    I made a start on the code (and it is only a start):
        Dim R As Range, MaxCol As Byte, Ctr As Byte, MaxRw As Integer, Col As Range
        
        Set R = Range("A:U")
        MaxCol = R.Columns.Count
        
        MaxRw = 3 ^ (MaxCol - 1)
        
        For Ctr = 1 To MaxCol
            Set Col = R.Columns(Ctr)
            Range(Col.Cells(1), Col.Cells(3 ^ (Ctr - 1))).Value = 1
        Next Ctr
    ...then I realised that to complete this you will need 10,460,353,203 rows, which is somewhat more than Excel can handle.

    I can have a further look next week if you like, but it looks like you may need to rethink.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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