根据相邻列自动填充 [英] autofill down according to adjacent column

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

问题描述

我正在寻找将根据相邻列的长度自动填充数据的VBA代码。我知道有几个方法可以解决这个问题,但最好的是:

I'm looking for VBA code that will autofill data down according to the length of an adjacent column. I know there are a few ways to go about this, but which is best?:

If LastRow > Selection.Row Then
   Range("D2").AutoFill Destination:=Range("D2:D" & LastRow)

或类似:

If Not IsEmpty(ActiveCell.Offset(0,1)) Then
   Range("D2").AutoFill Destination:=Range("D2:D" & LastRow)

我很确定这些都不是我想要的,所以我缺少什么?

I'm pretty sure neither of these work exactly how I want it so what am I missing?

推荐答案

没有任何条件的需要。我们可以得到列C的最后一行,并相应地填写列D中的数据。

There is no need for any if condition. We can get the last used row of column C and fill the data in column D accordingly.

Sub test()

    Dim lastRow As Long
    lastRow = Range("C" & Rows.Count).End(xlUp).Row
    Range("D2").AutoFill Destination:=Range("D2:D" & lastRow)

End Sub

这篇关于根据相邻列自动填充的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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