VBA 自动填充特定行数
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/27828504/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
VBA to Auto Fill Specific Number of Rows
提问by user3682157
I am trying to autofill a specific number of rows in a column based on a number found in another cell (which changes based on data)
我正在尝试根据在另一个单元格中找到的数字(根据数据更改)自动填充列中的特定行数
So say cell D2 = 250
所以说单元格D2 = 250
I need to label FF4:FF250with numbers 1,2,3,4,5... so that it looks like this
我需要用数字 1,2,3,4,5标记 FF4:FF 250... 使它看起来像这样
Column FF
Cell 4 1
Cell 5 2
Cell 6 3
Cell 7 4
... ...
I'm playing around with something like this but it doesn't work
我正在玩这样的东西,但它不起作用
Sub AutoFillSpecific()
MyValue = Range("D2").Value
Range("FF4").Select
Selection.AutoFill Destination:=Range(FF4:FFMyValue)
Any help?
有什么帮助吗?
回答by Chrismas007
Assuming you have a value in FF4
to autofill down:
假设你有一个FF4
自动填充的值:
Range("FF4").Value = 1
Range("FF4").AutoFill Destination:=Range("FF4:FF" & MyValue), Type:=xlFillSeries
You'll want to add Dim MyValue As Long
to avoid errors because it will make sure the value of D2 is a number when you move it into the MyValue
.
您需要添加Dim MyValue As Long
以避免错误,因为当您将 D2 移入MyValue
.