VBA自动填充特定的行数 [英] VBA to Auto Fill Specific Number of Rows

查看:143
本文介绍了VBA自动填充特定的行数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试根据在另一个单元格中找到的数字(根据数据而变化)自动填充列中的特定行数

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)

比如说单元格 D2 = 250

我需要将FF4:FF 250 标记为数字1,2,3,4,5 ...,以便看起来像这样

I need to label FF4:FF250 with numbers 1,2,3,4,5... so that it looks like this

       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)  

有帮助吗?

推荐答案

假设您在 FF4 中有一个值可以自动填充:

Assuming you have a value in FF4 to autofill down:

Range("FF4").Value = 1
Range("FF4").AutoFill Destination:=Range("FF4:FF" & MyValue), Type:=xlFillSeries

您将要添加 Dim MyValue As Long 以避免错误,因为当您将D2的值移入 MyValue 时,它将确保D2的值是一个数字.

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.

这篇关于VBA自动填充特定的行数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆