简体   繁体   English

Excel VBA自动填充跨列

[英]Excel VBA Autofill across columns

I want to edit the range in Autofill code below but I'm not sure how. 我想在下面的自动填充代码中编辑范围,但不确定如何。

'find last used cell in the row to the right
Range("B59").End(xlToRight).Select

'auto fill the formula for "Total TV"
ActiveCell.AutoFill Range(ActiveCell, ActiveCell.Offset(0, 1))

At present, the code finds the last valid cell in a row, then it autofills one cell to the right. 目前,该代码查找行中最后一个有效的单元格,然后自动向右填充一个单元格。

What I want to do: 我想做的事:

I would to find the last valid cell, then select the active cell and the cells from 3 rows below it too and then autofill one cell to the right. 我将找到最后一个有效的单元格,然后选择活动单元格以及它下面3行中的单元格,然后自动填充右侧的一个单元格。

In pictures it would look like this: 在图片中看起来像这样:

  1. find last valid cell in row 59: 在第59行中找到最后一个有效单元格:

在此处输入图片说明

  1. select active cell and cells 3 rows below: 选择活动单元格,然后在下面的3行中选择单元格:

在此处输入图片说明

  1. Autofill one cell to the right 自动填充右侧的一个单元格

在此处输入图片说明

Here is one way. 这是一种方法。 No need to Select 无需选择

Sub x()

Dim r As RANGE

Set r = RANGE("B59").End(xlToRight)
r.Resize(4).AutoFill r.Resize(4, 2)

End Sub

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

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