Print Numbers Based on Used Range

  • Type in any two cells
  • Numbers will print between the cells of first and last
  •  

     

    Print Unique number by increasing STEP value

     

    Private Sub CommandButton1_Click()
    Dim i As Integer
    Dim j As Integer
    j = 0
    For i = 1 To 10
    Cells(i, 1) = i - j
    j = j + 1
    Next
    End Sub

     

     

    Print numbers in TABLE format

     

    Private Sub CommandButton1_Click()
    ' r for rows, c for columns
    Dim r As Long, c As Integer
    For r = 1 To 5
    For c = 1 To 5
    Cells(r, c).Value = r * c
    Next c
    Next r
    End Sub

     

     

    Print numbers with formatting options

     

    Private Sub CommandButton1_Click()
    Dim wkb As Workbook
    Set wkb = Workbooks.Add
    Dim max As Integer
    max = wkb.Sheets("Sheet1").Range("d5:m15").Cells.Count
    Dim i As Long
    With wkb.Sheets("Sheet1").Range("d5:m15")
    For i = 1 To max
    .Cells(i).Value = i
    If i Mod 2 = 0 Then
    .Cells(i).Font.ColorIndex = 30
    Else
    .Cells(i).Font.ColorIndex = 10
    End If
    Next
    End With
    MsgBox "Hi Pavan task has been completed"
    End Sub