Excel Auto Complete Cells until given value

stefanfreund

New Member
Joined
Feb 23, 2017
Messages
5
Hello friends,

I have a question that is bothering me for some time now, and it is a bit difficult to explain, hope you will understand:confused:.

I have a sheet that looks like the table below.

1
7
13
2
8
14
3
9
15
4
10
16
5
11
17
6
12
18

<tbody>
</tbody>

Now, I am trying to find out a way (formula, vba or some kind of solution) that I tell excel exactly till what number to go down the column, and then it continues to the other column. So for example in the table above there are 6 data inputs per column, but if for example my data set changes and I need to have 12 per column, then I would like that I just tell excel to automatically go like 1,2,3,4,5,6,7,8,9,10,11,12 and then continue with 13,14,15.. on the other column (yes, I want to have consecutive numbers from 1 until lets say 1000). I know it sounds a bit complicated or confusing so please let me know if something is not clear.

Thank you very much in advance for your help!
You are the best
 

Excel Facts

Which Excel functions can ignore hidden rows?
The SUBTOTAL and AGGREGATE functions ignore hidden rows. AGGREGATE can also exclude error cells and more.
Try this:-
NB:- Change Constant "NumPC" as required.
Code:
[COLOR="Navy"]Sub[/COLOR] MG23Feb57
[COLOR="Navy"]Dim[/COLOR] n [COLOR="Navy"]As[/COLOR] [COLOR="Navy"]Long,[/COLOR] c [COLOR="Navy"]As[/COLOR] [COLOR="Navy"]Long,[/COLOR] ac [COLOR="Navy"]As[/COLOR] [COLOR="Navy"]Long[/COLOR]
Const NumPC = 12 '[COLOR="Green"][B] New column when 12th row is filled[/B][/COLOR]
ac = 1
[COLOR="Navy"]For[/COLOR] n = 1 To 1000
    c = c + 1
    [COLOR="Navy"]If[/COLOR] c = 13 Then: ac = ac + 1: c = 1
    Cells(c, ac) = n
[COLOR="Navy"]Next[/COLOR] n
[COLOR="Navy"]End[/COLOR] [COLOR="Navy"]Sub[/COLOR]
Regards Mick
 
Upvote 0
Try this:

Code:
Sub Test()
'Modified 2/23/17 8:15 AM EST
Application.ScreenUpdating = False
Dim i As Long
Dim b As Long
Dim r As Long
r = 1
b = 1
Dim ans As Long
ans = InputBox("How many rows per column")
    For i = 1 To 1000
        Cells(r, b).Value = i
        r = r + 1
        If r = ans + 1 Then r = 1: b = b + 1
        
    Next
Application.ScreenUpdating = True
End Sub
 
Upvote 0
Fantastic! Thank you very much Mick!

Try this:-
NB:- Change Constant "NumPC" as required.
Code:
[COLOR=Navy]Sub[/COLOR] MG23Feb57
[COLOR=Navy]Dim[/COLOR] n [COLOR=Navy]As[/COLOR] [COLOR=Navy]Long,[/COLOR] c [COLOR=Navy]As[/COLOR] [COLOR=Navy]Long,[/COLOR] ac [COLOR=Navy]As[/COLOR] [COLOR=Navy]Long[/COLOR]
Const NumPC = 12 '[COLOR=Green][B] New column when 12th row is filled[/B][/COLOR]
ac = 1
[COLOR=Navy]For[/COLOR] n = 1 To 1000
    c = c + 1
    [COLOR=Navy]If[/COLOR] c = 13 Then: ac = ac + 1: c = 1
    Cells(c, ac) = n
[COLOR=Navy]Next[/COLOR] n
[COLOR=Navy]End[/COLOR] [COLOR=Navy]Sub[/COLOR]
Regards Mick
 
Upvote 0
You're welcome

NB:- I think "My Answer is this" has code that is probably more useful as it has an InputBox
 
Upvote 0
(formula, vba or some kind of solution)

Hi, here is a formula way if interested - in this example A1 contains the number of rows to populate and the formula in A3 can be copied down and across as far as may be required.


Excel 2013
ABCDEF
16
2
31713192531
42814202632
53915212733
641016222834
751117232935
861218243036
Sheet2
Cell Formulas
RangeFormula
A3=IF(ROWS(A$3:A3)>$A$1,"",ROWS(A$3:A3)+(COLUMNS($A3:A3)*$A$1)-$A$1)
 
Upvote 0
oh, great! Thank you!

Try this:

Code:
Sub Test()
'Modified 2/23/17 8:15 AM EST
Application.ScreenUpdating = False
Dim i As Long
Dim b As Long
Dim r As Long
r = 1
b = 1
Dim ans As Long
ans = InputBox("How many rows per column")
    For i = 1 To 1000
        Cells(r, b).Value = i
        r = r + 1
        If r = ans + 1 Then r = 1: b = b + 1
        
    Next
Application.ScreenUpdating = True
End Sub
 
Upvote 0
Try this:-
NB:- Change Constant "NumPC" as required.
Code:
[COLOR=navy]Sub[/COLOR] MG23Feb57
[COLOR=navy]Dim[/COLOR] n [COLOR=navy]As[/COLOR] [COLOR=navy]Long,[/COLOR] c [COLOR=navy]As[/COLOR] [COLOR=navy]Long,[/COLOR] ac [COLOR=navy]As[/COLOR] [COLOR=navy]Long[/COLOR]
Const NumPC = 12 '[COLOR=green][B] New column when 12th row is filled[/B][/COLOR]
ac = 1
[COLOR=navy]For[/COLOR] n = 1 To 1000
    c = c + 1
    [COLOR=navy]If[/COLOR] c = 13 Then: ac = ac + 1: c = 1
    Cells(c, ac) = n
[COLOR=navy]Next[/COLOR] n
[COLOR=navy]End[/COLOR] [COLOR=navy]Sub[/COLOR]
Regards Mick

Hi,

New to VBA ant try to understand.
What is the role of this line?
Code:
Const NumPC = 12 '[COLOR=green][B] New column when 12th row is filled[/B][/COLOR]
 
Upvote 0

Forum statistics

Threads
1,214,628
Messages
6,120,618
Members
448,973
Latest member
ChristineC

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