繁体   English   中英

VBA根据单元格中的值填充列范围

[英]VBA Populate Column Range based on value in Cell

我正在尝试编写一个脚本,以根据输入值填充一系列单元格。

输入值表示该范围内的最大数字,脚本以9为增量递增到该值。

示例:输入值42。结果范围,一列中每个单元格一个值:

001-010

011-020

021-030

031-040

041-042

您应该提供尝试过的内容,但这应该可以帮助您入门:

Sub inc()

Dim V1 As Integer: V1 = InputBox("Enter a value")
Dim a As Integer: a = 1
Dim b As Integer: b = 1

Cells.Clear

For i = 10 To Round(V1, 10) Step 10
    Cells(a, 1) = Format(b, "000") & "-" & Format(i, "000")
    a = a + 1
    b = b + 10
Next i

Cells(a, 1) = Format(b, "000") & "-" & Format(V1, "000")

End Sub

清除活动纸时要小心。 您可能要更改它。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM