每第二行的Excel宏代码增加1 [英] Excel macro code for every 2nd row to increase by 1
问题描述
我有一个数字列表(超过100行).我希望每组3的行中的每个第二个数字都比前一行增加1.
I have a list of numbers (over 100 rows). I want every 2nd number in each group of 3's row to increase by 1 from its previous row.
以3为一组思考.给出第一个值.第二个值比第一个高1,第三个值可以是任意值.此模式继续到下一个3.例如,如果行1 = 1,行2 = 2(因为从上一行开始增加1).第3行=任何#.第4行= 5,第5行= 6(因为与前一行相比增加了1).第6行=任何数字.第7行= 7,第8行= 8(因为以前是1),第9行=任意.
Think in groups of 3. The first value is given. The 2nd value is 1 higher than the first, and the 3rd value can be anything. This pattern continues for the next 3. For example, if Row 1 = 1, Row 2 = 2 (because increase 1 from previous row). Row 3 = any #. Row 4 = 5, Row 5 = 6 (because increase 1 from previous row). Row 6 = any number. Row 7 = 7, Row 8 = 8 (because 1 from orevious), Row 9 = any.
我不知道该如何循环.这就是我尝试过的.
I can't figure out how to loop through this. THis is what I tried.
Sub DoSomething
For ColNum = 4 To 500 Step 2
Range(Cells(3, ColNum), Cells(1159, ColNum)).FormulaR1C1 = "='H2'+1"
Next ColNum
End Sub
推荐答案
如果我正确理解了您的问题,则可能需要以下内容:
If I understand your question correctly, you may want somthing like:
Sub test()
For i = 3 To 1159 Step 3
Cells(i + 1, 1).FormulaR1C1 = "=R[-1]C+1"
Next i
End Sub
从第3行开始,直到第1159行(共3组),抓取下一个单元格,然后输入一个公式,使上一行中的单元格的值增加1.
Starting in Row 3, up to row 1159, in sets of 3, grab the next cell and enter a formula that increases the value of the cell in the row above by 1.
下面是说明代码的屏幕截图.左在前,右在后. B列已复制=Formulatext(A3)
.
Here are screenshots to illustrate the code. Left is before, right is after. Column B has =Formulatext(A3)
copied down.
每三个一组思考一次,每三个一组中的第二个单元格都按照公式处理.
Thinking in groups of three, every second cell in each group of three is treated to the formula.
这篇关于每第二行的Excel宏代码增加1的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!