Consulting

Results 1 to 4 of 4

Thread: Insert progressive numbers in a column but every n rows

  1. #1
    VBAX Regular
    Joined
    Jan 2015
    Posts
    92
    Location

    Insert progressive numbers in a column but every n rows

    Good morning,


    I'm looking for a code that inserts a progressive number every n rows, starting from 1 up to a given number. I think it's not complicated, but I do not have the knowledge to write the code, can someone help me?

    I enclose an example to better explain what I mean


    thank you
    Attached Files Attached Files

  2. #2
    Mac Moderator VBAX Guru mikerickson's Avatar
    Joined
    May 2007
    Location
    Davis CA
    Posts
    2,778
    Something like

    Dim targetN as Long
    Dim x as Long
    Dim RowNum as Long, RowInterval as Long
    x=0
    TargetN = 34
    RowNum = 1
    RowInterval = 4
    
    Do Until TargetN <= X
        X = X +1
        Cells(RowNum, 1).Value = x
        RowNum = RowNum + RowInterval
    Loop

  3. #3
    VBAX Mentor 大灰狼1976's Avatar
    Joined
    Dec 2018
    Location
    SuZhou China
    Posts
    479
    Location
    Hi RIC63!
    You can do like this
    Private Sub CommandButton1_Click()
    Dim cnt&, stp&, i&, arr
    cnt = [i1]: stp = [i2]
    ReDim arr(1 To cnt, 1 To 1)
    arr(1, 1) = 1
    For i = stp To cnt Step stp
      arr(i, 1) = i
    Next i
    [a1].Resize(cnt) = arr
    End Sub
    Please refer to the attachment.
    Attached Files Attached Files

  4. #4
    VBAX Regular
    Joined
    Jan 2015
    Posts
    92
    Location
    Thank you mikerickson

    it works well, it's just what I wanted
    Thanks again
    riccardo

Posting Permissions

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