Autofill Numbers in Sequence, increments of 30 over multiple columns

Plukey

Board Regular
Joined
Apr 19, 2019
Messages
138
Office Version
  1. 2016
Platform
  1. Windows
I have a few VBA's that accomplish the task on a single column. But what Id like to do, is enter a start number and consecutively autofill 270 times across 9 columns in increments of 30.
These Serial Numbers get used quickly, If I could run a Vba that ask for a start # and autofill it would save some time.

Ex.
1 6 11
2 7 12
3 8 13
4 9 14
5 10 15
etc...….

VBA Code:
Sub AddSerialNum1()
Dim i As Integer
On Error GoTo Last
i = InputBox("Enter Value", "Enter Serial Numbers")
For i = 1 To i
ActiveCell.Value = i
ActiveCell.Offset(1, 0).Activate
Next i
Last:
Exit Sub
End Sub


or


VBA Code:
Sub AddSerialNum2()
Dim i As Long, J As Long
Application.ScreenUpdating = 0

i = Application.InputBox(Prompt:="Start", Type:=1)
J = Application.InputBox(Prompt:="end", Type:=1)
With Sheets("Sheet1").Cells(Rows.Count, "A").End(xlUp).Offset(1)
        .Value = i
        .AutoFill .Resize(J, 1), xlFillSeries
    End With
    Application.ScreenUpdating = 1


End Sub
 

Excel Facts

Does the VLOOKUP table have to be sorted?
No! when you are using an exact match, the VLOOKUP table can be in any order. Best-selling items at the top is actually the best.
What version of Excel are you using?

I suggest that you update your Account details (or click your user name at the top right of the forum) so helpers always know what Excel version(s) & platform(s) you are using as the best solution often varies by version. (Don’t forget to scroll down & ‘Save’)
 
Upvote 0
What version of Excel are you using?

I suggest that you update your Account details (or click your user name at the top right of the forum) so helpers always know what Excel version(s) & platform(s) you are using as the best solution often varies by version. (Don’t forget to scroll down & ‘Save’)
Apologies Thank you, I updated my profile with the details. I'm using 2016 Windows
 
Upvote 0
Thanks for that, how about
VBA Code:
Sub Plukey()
   Dim r As Long, c As Long
   Dim Ary As Variant, Start As Variant
   
   ReDim Ary(1 To 30, 1 To 9)
   
   Start = InputBox("Please enter start number")
   If Start = "" Then Exit Sub
   For c = 1 To UBound(Ary, 2)
      For r = 1 To UBound(Ary)
         Ary(r, c) = Start
         Start = Start + 1
      Next r
   Next c
   Range("A2").Resize(UBound(Ary), UBound(Ary, 2)).Value = Ary
End Sub
 
Upvote 0
Solution
Thanks for that, how about
VBA Code:
Sub Plukey()
   Dim r As Long, c As Long
   Dim Ary As Variant, Start As Variant
  
   ReDim Ary(1 To 30, 1 To 9)
  
   Start = InputBox("Please enter start number")
   If Start = "" Then Exit Sub
   For c = 1 To UBound(Ary, 2)
      For r = 1 To UBound(Ary)
         Ary(r, c) = Start
         Start = Start + 1
      Next r
   Next c
   Range("A2").Resize(UBound(Ary), UBound(Ary, 2)).Value = Ary
End Sub
Absolutely perfect!!! thank you!!!
 
Upvote 0
You're welcome & thanks for the feedback.
 
Upvote 0
You could also write the macro this way (no loops)...
VBA Code:
Sub Plukey()
  Dim StartNumber As Variant
  StartNumber = InputBox("Please enter start number")
  If StartNumber Like "#*" Then
    With Range("A2").Resize(30, 9)
      .Formula = "=" & StartNumber & "+ROW(A1)-1+30*(COLUMN(A1)-1)"
      .Value = .Value
    End With
  End If
End Sub
 
Last edited:
Upvote 0
Not sure what you mean by "all columns" (I'll assume 9 as was stated in the original posting)...
VBA Code:
Sub OneToThirtyAllColumns()
  Range("A1:I30").Value = [ROW(1:30)]
End Sub
 
Upvote 0
that's great ! but what I if choose specific columns (A,C,F,L,M) how should be ?
 
Upvote 0

Forum statistics

Threads
1,215,491
Messages
6,125,101
Members
449,205
Latest member
ralemanygarcia

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top