[英]Copying rows and columns, including blanks, in excel vba without xlDown
I'd like to copy Rows and Columns of a worksheet to a new workbook. 我想将工作表的行和列复制到新的工作簿。 I can open and activate the new book and new sheets, but the data I am copying is currently A1:F520 on one sheet and A1:G1031 on another.
我可以打开并激活新书和新纸,但是当前正在复制的数据在一张纸上是A1:F520,在另一张纸上是A1:G1031。 There are multiple blanks in between and within several "groups" of data sets.
数据集的几个“组”之间和之内有多个空白。
For the sake of the visual organization of our data, I want to keep those blanks in. The ranges will be changing over time, so I don't want to define something specific. 为了直观地组织数据,我希望保留这些空白。范围会随着时间而变化,因此我不想定义特定的内容。 I'd rather keep it general like Range("A1", Range("A1".End(xlDown)). I suppose I could just include some ridiculously large range to ensure everything is there, but I'd rather accomplish this in a more dynamic (if that is the right word) sort of way.
我宁愿像Range(“ A1”,Range(“ A1” .End(xlDown))那样保持一般性,我想我可以只包含一些可笑的大范围以确保所有内容都在其中,但是我宁愿在一种更动态(如果正确的话)的方式。
This is what I have so far: 这是我到目前为止的内容:
Option Explicit
Public LGSheet As Worksheet
Public SGSheet As Worksheet
Public NewWorkbook As Workbook
Public UserYear As Integer
Sub DefineYear()
UserYear = Application.InputBox(Prompt:="Set Date for New Workbook", Type:=1)
Set NewWorkbook = Workbooks.Add
Set SGSheet = Worksheets.Add
Set LGSheet = Worksheets.Add
Call PasteLGTandSGT
End Sub
Sub PasteLGTandSGT()
Workbooks("Finished Products YTD Generator").Activate
Worksheets("LGT").Activate
Range("A1", Range("A1").End(xlDown)).Copy
LGSheet.Activate
Obviously I've put the xlDown bit here, and my google-fu isn't strong enough to find out anything more. 显然,我在这里放了xlDown位,而我的google-fu不够强大,无法发现更多内容。
For example: 例如:
With Workbooks("Finished Products YTD Generator").Worksheets("LGT")
.Range(.Range("A1"), .Cells(Rows.Count, 1).End(xlUp).Offset(0, 7)).Copy _
LGSheet.Range("A1") 'or whatever
End With
Note that you don't need to activate sheets to copy or paste, and it's a good habit to get out of. 请注意,您无需激活工作表即可进行复制或粘贴,这是一个摆脱的好习惯。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.