简体   繁体   中英

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.

In pictures it would look like this:

  1. find last valid cell in row 59:

在此处输入图片说明

  1. select active cell and cells 3 rows below:

在此处输入图片说明

  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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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