我正在处理Excel中的产品说明书。每个规范由三列组成:例如,A列为500,B列为码,最后在C列I中,测试是否设置A列,然后将它们合并为"500码“。产品规格中使用C栏。如F栏、I栏等。
现在我知道我可以使用自动填充来填充整个C列,但是对于第三列是否必须手动填充呢?
所以我要找的是一种在第三列自动填充的方法。
发布于 2018-02-09 21:07:59
此代码假设在第2行的每一列上都有公式(您希望自动填充该列)。
Sub Autofill_every_nth_column()
Dim RangeToFill As String
For i = 3 To 150 Step 3 'start from column 3 (i.e. column "C") and loop to column 150 (i.e. column "ET"). After every loop it jump 3 columns. So first loop it will autofill Column C, then autofill Column F etc.
RangeToFill = Range(Cells(2, i), Cells(2, i)).Select 'Cell formula is located. This mean at Row 2 and column i, where i is the number the loop is at
Selection.AutoFill Destination:=Range(Cells(2, i), Cells(200, i)) 'Autofill formula from row 2 to row 200.
Next 'Jump to next loop.
End Sub我写了一些评论,希望你能为了你的目的而修改它。请记住,excel中的自动填充函数仅在单元格中有值时才自动填充。所以即使你说:
Destination:=Range(Cells(2, i), Cells(200, i)) 'Autofill formula from row 2 to row 200.它只循环到最后一行,其中有值(最大到第200行)。
https://stackoverflow.com/questions/48712379
复制相似问题