Autofill复制,一直到下一个空行- Excel VBA宏

huangapple go评论125阅读模式
英文:

Autofill Copy down up until next empty row- Excel VBA Macro

问题

我想要将一个数值粘贴到A列中的特定单元格(空列),然后我想要自动填充复制这个数值,一直到下一个空行或B列中的数据。

我可以通过指定复制范围来实现这一点,但我希望这是动态的,因为复制的行数可能不同。数据之间有空行分隔的块。我希望在A列的每个数据块中复制和粘贴一个数值。谢谢!

Selection.AutoFill Destination:=Range(Selection, Selection.End(xlDown)), Type:=xlFillCopy
英文:

i would like to paste a value in a given cell in Column A (empty column), i would like to autofill copy this down up until the next empty row or data in column B.

I can do this by specifying a range to copy down to but i would like for this to be dynamic since the amount of rows copied can be different. There are blocks of data, with a blank row in between. I would like to essentially copy and paste a value for each block of data in column A. Thank you!

Selection.AutoFill Destination:=Range(Selection, Selection.End(xlDown)), Type:=xlFillCopy

答案1

得分: 1

由于A列为空,End(xlDown)将返回1048576行。您需要查看B列的End,然后引用回A列。

您可以使用Offset从您的选择中获取B列,然后返回A列。

Selection.AutoFill Destination:=Range(Selection, Selection.Offset(0, 1).End(xlDown).Offset(0, -1)), Type:=xlFillCopy
英文:

Since Column A is empty end(xldown) will return row 1048576. You need to look at Column B for the end then refer back to Column A.

You can use offset to grab Column B from your Selection then back to Column A.

Selection.AutoFill Destination:=Range(Selection, Selection.Offset(0, 1).End(xlDown).Offset(0, -1)), Type:=xlFillCopy

huangapple
  • 本文由 发表于 2023年2月18日 00:09:30
  • 转载请务必保留本文链接:https://go.coder-hub.com/75486674.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定