Skip column to each N counted rows

Asked

Viewed 972 times

2

I need help with vba. When inserting values using Line counter, I want to change column, every N number of rows.

E.g.: every 100 rows counted and automatically inserted values, the column is changing and the row count resumes in a new column. I can change lines using row counter but can’t do the same p columns.

Here is the status of the code:

Sub numberlist()

Application.Screenupdating = False

Application.Calculation = xlCalculationManual

Dim a1 As Single
Dim b1 As Single
Dim c1 As Single
Dim count As Integer
Dim lrow As Long
Dim lcolumn As Integer

a1 = 0
b1 = 0
c1 = 0

    For a1 = 0 To 9 Step 1
    For b1 = 0 To 9 Step 1
    For c1 = 0 To 9 Step 1
    lrow = Cells(Rows.count, "A").End(xlUp).Row + 1
    Cells(lrow, "A") = a1 & b1 & c1

    If lrow Mod 100 = 0 Then
        Application.EnableEvents = False
        lcolumn = Range(1, Columns.count).Next(xlToRight).Column + 1
        lrow = 0
        lrow = Cells(Rows.count, Columns.count).End(xlUp).Row + 1
        Cells(lrow, "A") = a1 & b1 & c1
        Else
        End If

    Next
    Next
    Next



Application.EnableEvents = True
Application.Calculation = xlCalculationAutomatic
Application.ScreenUpdating = True
End Sub

1 answer

2


I did it! I changed my logic on parole mod. Ex.: Every 100 rows the column counter changes to another 1. Stay this way:

 Sub numberlist()

    Application.ScreenUpdating = False
    Application.Calculation = xlCalculationManual

    Dim a1 As Single    
    Dim b1 As Single
    Dim c1 As Single
    Dim count As Integer
    Dim lrow As Long
    Dim lcolumn As Long

    a1 = 0

    b1 = 0

    c1 = 0

    lcolumn = 1

        For a1 = 0 To 9 Step 1
        For b1 = 0 To 9 Step 1
        For c1 = 0 To 9 Step 1
        lrow = Cells(Rows.count, lcolumn).End(xlUp).Row + 1
        Cells(lrow, lcolumn) = a1 & b1 & c1

        If lrow Mod 100 = 0 Then

            lcolumn = lcolumn + 1
            lrow = 1

            Else
            End if
Next
Next
Next

    Application.Calculation = xlCalculationAutomatic
    Application.ScreenUpdating = True

    End Sub

Browser other questions tagged

You are not signed in. Login or sign up in order to post.