英文:
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
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论