Click here to Skip to main content
15,885,914 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I want to increment every 15 rows of E column by 1.
For eg. if E15 is 1, then E30 should be 2, E45 should be 3, E60 should be 4 etc., upto E200.
What can be given in the code? I tried many codes but it doesn't seem to work.
Can you please help me ?
Thank you in advance.
Posted

ROW() will give you the current row, and you can divide that by 15, then round the remaining number up to the nearest whole integer with ROUNDUP(). The second parameter of Roundup is the number of decimal places.

So:
VB
=ROUNDUP(ROW()/15,0)
 
Share this answer
 
Comments
Member 11226682 23-Jan-15 3:08am    
I want to write a VBA script. Not declare a formula. Is it possible??
I know it has been two weeks since you posted, but fwiw, I think this could help.

Using a step value of 15 in a for loop and incrementing the starting value in each iteration should take care of what you need easily. This first code is hard coded with the values you provided and should be easiest to follow.
VB
Sub IncrementEveryFifteenRows()

'Declare startValue to capture the value of E15
Dim startValue
startValue = Cells(15, 5).Value

'Loop to jump to every fifteenth row, incrementing startValue each iteration
For i = 15 To 200 Step 15
    Cells(i, 5).Value = startValue
    startValue = startValue + 1
Next i

End Sub



This next code adds a level of abstraction by incrementing every fifteenth row of the selected range. This way, you could begin and end at whichever row you like. For instance, if you select B3:B100 and the value of B3 is 5, then you will set B18 as 6, B33 as 7, B48 as 8, B63 as 9, B78 as 10, and B93 as 11.
VB
Sub IncrementEveryFifteenRows()

Dim startValue
Dim selectedRows

'Using Selection, cell references are relative to the selected range 
'and not the worksheet as a whole
startValue = Selection.Cells(1, 1).Value
selectedRows = Selection.Rows.Count

'Loop to jump to every fifteenth row, incrementing startValue each iteration
With Selection
    For i = 1 To selectedRows Step 15
        .Cells(i, 1).Value = startValue
        startValue = startValue + 1
    Next i
End With

End Sub


This code can be abstracted further with user prompts to gather values such as step value, increment value, specific rows on which to begin and end, and which column this should apply to. That would just require declaring more variables to put in place of the hard coded numbers in the first example.

Hope this helps, and good luck.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900